diff --git a/phpstan.neon b/phpstan.neon index 99b906fe..917b2aca 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,6 @@ parameters: level: max reportUnmatchedIgnoredErrors: false - checkMissingIterableValueType: false paths: - src @@ -11,6 +10,8 @@ parameters: - 'tests/Application/src/**.php' ignoreErrors: + - identifier: missingType.iterableValue + - identifier: missingType.generics - '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./' - '/Parameter \#1 \$request \([^)]+\) of method [^:]+::execute\(\) should be contravariant with parameter \$request \(mixed\) of method Payum\\Core\\Action\\ActionInterface::execute\(\)/' - '/Parameter \$event of method CommerceWeavers\\SyliusTpayPlugin\\Refunding\\Workflow\\Listener\\DispatchRefundListener::__invoke\(\) has invalid type Symfony\\Component\\Workflow\\Event\\TransitionEvent\./' diff --git a/src/Form/DataTransformer/PaymentDetailsTransformer.php b/src/Form/DataTransformer/PaymentDetailsTransformer.php index eb9a1443..9220270f 100644 --- a/src/Form/DataTransformer/PaymentDetailsTransformer.php +++ b/src/Form/DataTransformer/PaymentDetailsTransformer.php @@ -5,17 +5,20 @@ namespace CommerceWeavers\SyliusTpayPlugin\Form\DataTransformer; use Symfony\Component\Form\DataTransformerInterface; +use Webmozart\Assert\Assert; class PaymentDetailsTransformer implements DataTransformerInterface { - public function transform($value): string + public function transform(mixed $value): string { - if (!$value || !array_key_exists('blik', $value)) { + Assert::isArray($value); + if ($value === [] || !array_key_exists('blik', $value)) { return ''; } return $value['blik']; } + public function reverseTransform($value): array { return ['blik' => $value]; diff --git a/src/Payum/Action/Api/CreateBlik0TransactionAction.php b/src/Payum/Action/Api/CreateBlik0TransactionAction.php index bf677cd8..33b38bc5 100644 --- a/src/Payum/Action/Api/CreateBlik0TransactionAction.php +++ b/src/Payum/Action/Api/CreateBlik0TransactionAction.php @@ -13,6 +13,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; use Tpay\OpenApi\Api\TpayApi; +use Webmozart\Assert\Assert; /** * @property TpayApi $api @@ -21,7 +22,7 @@ final class CreateBlik0TransactionAction extends BaseApiAwareAction implements G { use GenericTokenFactoryAwareTrait; - public function __construct ( + public function __construct( private RouterInterface $router, private string $successRoute, private string $errorRoute, @@ -38,17 +39,25 @@ public function execute($request): void /** @var PaymentInterface $model */ $model = $request->getModel(); $details = $model->getDetails(); + $token = $request->getToken(); + Assert::notNull($token); $order = $model->getOrder(); + Assert::notNull($order); $customer = $order->getCustomer(); + Assert::notNull($customer); $localeCode = $order->getLocaleCode(); + Assert::notNull($localeCode); $billingAddress = $order->getBillingAddress(); - $notifyToken = $this->createNotifyToken($model, $request->getToken(), $localeCode); + Assert::notNull($billingAddress); + $notifyToken = $this->createNotifyToken($model, $token, $localeCode); + $amount = $model->getAmount(); + Assert::notNull($amount); $blikToken = $model->getDetails()['tpay']['blik']; $response = $this->api->transactions()->createTransaction([ - 'amount' => number_format($model->getAmount() / 100, 2, thousands_separator: ''), + 'amount' => number_format($amount / 100, 2, thousands_separator: ''), 'description' => sprintf('zamówienie #%s', $order->getNumber()), // TODO: Introduce translations 'payer' => [ 'email' => $customer->getEmail(), diff --git a/src/Payum/Action/CaptureAction.php b/src/Payum/Action/CaptureAction.php index ffa37764..6db4fc16 100644 --- a/src/Payum/Action/CaptureAction.php +++ b/src/Payum/Action/CaptureAction.php @@ -4,7 +4,6 @@ namespace CommerceWeavers\SyliusTpayPlugin\Payum\Action; -use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\CreateBlik0TransactionFactory; use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\CreateTransactionFactoryInterface; use Payum\Core\Action\ActionInterface; use Payum\Core\GatewayAwareInterface; @@ -33,7 +32,7 @@ public function execute($request): void if ($this->transactionIsBlik($model)) { $this->gateway->execute( - $this->createBlik0TransactionFactory->createNewWithModel($request->getToken()) + $this->createBlik0TransactionFactory->createNewWithModel($request->getToken()), ); return; @@ -53,10 +52,10 @@ public function supports($request): bool return $request instanceof Capture && $request->getModel() instanceof PaymentInterface; } - private function transactionIsBlik($model): bool + private function transactionIsBlik(PaymentInterface $model): bool { - return array_key_exists('tpay', $model->getDetails()) - && array_key_exists('blik', $model->getDetails()['tpay']) + return array_key_exists('tpay', $model->getDetails()) && + array_key_exists('blik', $model->getDetails()['tpay']) ; } } diff --git a/src/Payum/Request/Api/CreateBlik0Transaction.php b/src/Payum/Request/Api/CreateBlik0Transaction.php index 0dfcbcb5..49303b4e 100644 --- a/src/Payum/Request/Api/CreateBlik0Transaction.php +++ b/src/Payum/Request/Api/CreateBlik0Transaction.php @@ -8,15 +8,9 @@ class CreateBlik0Transaction extends Generic { - public function __construct ( - private string $afterUrl, + public function __construct( mixed $model, ) { parent::__construct($model); } - - public function getAfterUrl(): string - { - return $this->afterUrl; - } }