Skip to content

Commit

Permalink
Fix Psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Jun 13, 2024
1 parent 64a13fa commit d776059
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class PaymentController extends AbstractController

public const TOKEN_HASH_SESSION_KEY = 'webgriffe_klarna_token_hash';

/**
* @param OrderRepositoryInterface<OrderInterface> $orderRepository
* @param PaymentRepositoryInterface<PaymentInterface> $paymentRepository
*/
public function __construct(
private readonly OrderRepositoryInterface $orderRepository,
private readonly RequestStack $requestStack,
Expand Down
2 changes: 2 additions & 0 deletions src/Helper/PaymentDetailsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Webmozart\Assert\InvalidArgumentException;

/**
* @psalm-suppress TypeDoesNotContainType
*
* @psalm-import-type StoredPaymentDetails from PaymentDetails
*/
final class PaymentDetailsHelper
Expand Down
9 changes: 7 additions & 2 deletions src/Payum/Action/CancelAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Webmozart\Assert\Assert;

/**
* @psalm-suppress TypeDoesNotContainType
*
* @psalm-import-type StoredPaymentDetails from PaymentDetails
*/
final class CancelAction implements ActionInterface
Expand All @@ -42,9 +44,12 @@ public function execute($request): void
$payment = $request->getModel();
Assert::isInstanceOf($payment, SyliusPaymentInterface::class);

/** @var string|int $paymentId */
$paymentId = $payment->getId();

$this->logger->info(sprintf(
'Start cancel action for Sylius payment with ID "%s".',
$payment->getId(),
$paymentId,
));

$paymentDetails = $payment->getDetails();
Expand All @@ -53,7 +58,7 @@ public function execute($request): void
$this->logger->info('Redirecting the user to the Sylius Klarna Payments waiting page.');

$session = $this->requestStack->getSession();
$session->set(PaymentController::PAYMENT_ID_SESSION_KEY, $payment->getId());
$session->set(PaymentController::PAYMENT_ID_SESSION_KEY, $paymentId);
$cancelToken = $request->getToken();
Assert::isInstanceOf($cancelToken, TokenInterface::class);
$session->set(PaymentController::TOKEN_HASH_SESSION_KEY, $cancelToken->getHash());
Expand Down
11 changes: 8 additions & 3 deletions src/Payum/Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

/**
* @psalm-suppress PropertyNotSetInConstructor
* @psalm-suppress TypeDoesNotContainType
*
* @psalm-import-type StoredPaymentDetails from PaymentDetails
*/
Expand Down Expand Up @@ -74,9 +75,11 @@ public function execute($request): void
/** @var SyliusPaymentInterface $payment */
$payment = $request->getModel();

/** @var string|int $paymentId */
$paymentId = $payment->getId();
$this->logger->info(sprintf(
'Start capture action for Sylius payment with ID "%s".',
$payment->getId(),
$paymentId,
));

$captureToken = $request->getToken();
Expand Down Expand Up @@ -106,7 +109,7 @@ public function execute($request): void
));

$session = $this->requestStack->getSession();
$session->set(PaymentController::PAYMENT_ID_SESSION_KEY, $payment->getId());
$session->set(PaymentController::PAYMENT_ID_SESSION_KEY, $paymentId);
$session->set(PaymentController::TOKEN_HASH_SESSION_KEY, $captureToken->getHash());

$order = $payment->getOrder();
Expand Down Expand Up @@ -166,10 +169,12 @@ private function createPaymentSession(
$paymentSession = $createPaymentSession->getPaymentSession();
Assert::isInstanceOf($paymentSession, PaymentSession::class);

/** @var string|int $paymentId */
$paymentId = $payment->getId();
$this->logger->info(sprintf(
'Created Klarna Payment Session with ID "%s" for Sylius payment "%s".',
$paymentSession->getSessionId(),
$payment->getId(),
$paymentId,
));

return PaymentDetails::createFromPaymentSession($paymentSession);
Expand Down
9 changes: 7 additions & 2 deletions src/Payum/Action/NotifyAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use Webmozart\Assert\Assert;

/**
* @psalm-suppress PropertyNotSetInConstructor
* @psalm-suppress TypeDoesNotContainType
*
* @psalm-import-type StoredPaymentDetails from PaymentDetails
*/
final class NotifyAction implements ActionInterface, GatewayAwareInterface
Expand All @@ -43,9 +46,11 @@ public function execute($request): void
$payment = $request->getModel();
Assert::isInstanceOf($payment, SyliusPaymentInterface::class);

/** @var string|int $paymentId */
$paymentId = $payment->getId();
$this->logger->info(sprintf(
'Start notify action for Sylius payment with ID "%s".',
$payment->getId(),
$paymentId,
));

// This is needed to populate the http request with GET and POST params from current request
Expand All @@ -56,7 +61,7 @@ public function execute($request): void

$this->logger->info(sprintf(
'Received Klarna notification for payment with ID "%s".',
$payment->getId(),
$paymentId,
), ['Request parameters' => $requestParameters]);

$storedPaymentDetails = $payment->getDetails();
Expand Down
1 change: 0 additions & 1 deletion tests/Behat/Context/PayumPaymentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private function getCurrentPayment(): PaymentInterface
*/
private function getCurrentPaymentSecurityTokens(PaymentInterface $payment): array
{
/** @var PaymentSecurityTokenInterface[] $allPaymentTokens */
$allPaymentTokens = $this->getPaymentTokenRepository()->findAll();
$paymentSecurityTokens = array_filter($allPaymentTokens, static function (PaymentSecurityTokenInterface $token) use ($payment): bool {
return $token->getDetails()->getId() === $payment->getId() &&
Expand Down

0 comments on commit d776059

Please sign in to comment.