Skip to content

Commit

Permalink
NTR: fix stan /csfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Jun 14, 2024
1 parent 868c9e3 commit d4de574
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ phpcheck: ## Starts the PHP syntax checks
@find . -name '*.php' -not -path "./vendor/*" -not -path "./tests/*" | xargs -n 1 -P4 php -l

phpmin: ## Starts the PHP compatibility checks
@php vendor/bin/phpcs -p --standard=PHPCompatibility --extensions=php --runtime-set testVersion 7.2 ./src
@php vendor/bin/phpcs -p --standard=PHPCompatibility --extensions=php --runtime-set testVersion 7.4 ./src

csfix: ## Starts the PHP CS Fixer
@PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer fix --config=./.php_cs.php --dry-run
Expand Down
12 changes: 5 additions & 7 deletions src/Components/CancelManager/CancelItemFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
namespace Kiener\MolliePayments\Components\CancelManager;

use Kiener\MolliePayments\Factory\MollieApiFactory;
use Mollie\Api\MollieApiClient;
use Psr\Log\LoggerInterface;

/**
* @final
*/
class CancelItemFacade
{
/** @var \Mollie\Api\MollieApiClient */
private $client;
private MollieApiClient $client;

/** @var LoggerInterface */
private $logger;

private LoggerInterface $logger;

public function __construct(MollieApiFactory $clientFactory, LoggerInterface $logger)
{
Expand Down Expand Up @@ -57,12 +57,10 @@ public function cancelItem(string $orderId, string $mollieLineId, int $quantity,
$this->logger->info('Item cancelled successful', ['orderId' => $orderId, 'mollieLineId' => $mollieLineId, 'quantity' => $quantity]);

$response = $response->withData($lines);

} catch (\Throwable $e) {
$response = $response->failedWithMessage($e->getMessage());
}

return $response;
}

}
}
26 changes: 19 additions & 7 deletions src/Components/CancelManager/CancelItemResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
*/
class CancelItemResponse implements \JsonSerializable
{
private $message;
private $success = true;
private string $message;
private bool $success = true;

/**
* @var array<mixed>
*/
private array $data = [];

public function isSuccessful(): bool
Expand All @@ -19,14 +22,17 @@ public function isSuccessful(): bool
}

/**
* @return mixed
* @return string
*/
public function getMessage()
public function getMessage(): string
{
return $this->message;
}


/**
* @return false|string
*/
public function jsonSerialize(): mixed
{
return json_encode(['success' => $this->success, 'message' => $this->message]);
Expand All @@ -40,16 +46,22 @@ public function failedWithMessage(string $message): self
return $clone;
}

/**
* @param array<mixed> $data
* @return $this
*/
public function withData(array $data): self
{
$clone = clone $this;
$clone->data = $data;
return $clone;
}

public function getData():array
/**
* @return array<mixed>
*/
public function getData(): array
{
return $this->data;
}

}
}
4 changes: 1 addition & 3 deletions src/Controller/Api/Order/CancelLineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@

class CancelLineController extends AbstractController
{

private MollieApiFactory $clientFactory;
private CancelItemFacade $cancelItemFacade;

public function __construct(MollieApiFactory $clientFactory, CancelItemFacade $cancelItemFacade)
{

$this->clientFactory = $clientFactory;
$this->cancelItemFacade = $cancelItemFacade;
}
Expand Down Expand Up @@ -67,4 +65,4 @@ public function cancelAction(Request $request, Context $context): Response
$result = $this->cancelItemFacade->cancelItem($orderId, $mollieLineId, $quantity, $resetStock);
return new JsonResponse($result);
}
}
}

0 comments on commit d4de574

Please sign in to comment.