Skip to content

Commit

Permalink
Fix PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Nov 20, 2024
1 parent d162ccf commit 3ae1523
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 14 deletions.
7 changes: 4 additions & 3 deletions config/services/managers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ services:
class: FluxSE\SyliusStripePlugin\Manager\Checkout\CreateManager
arguments:
- '@flux_se.sylius_stripe.stripe.factory.client'
- '@flux_se.sylius_stripe.provider.checkout.create.checkout_session_params'
- '@flux_se.sylius_stripe.provider.checkout.create.params'
FluxSE\SyliusStripePlugin\Manager\Checkout\CreateManagerInterface:
alias: flux_se.sylius_stripe.manager.checkout.create

flux_se.sylius_stripe.manager.checkout.retrieve:
class: FluxSE\SyliusStripePlugin\Manager\Checkout\RetrieveManager
arguments:
- '@flux_se.sylius_stripe.stripe.factory.client'
- '@flux_se.sylius_stripe.provider.checkout.retrieve.params'
FluxSE\SyliusStripePlugin\Manager\Checkout\RetrieveManagerInterface:
alias: flux_se.sylius_stripe.manager.checkout.retrieve

Expand All @@ -26,7 +27,7 @@ services:
class: FluxSE\SyliusStripePlugin\Manager\WebElements\CreateManager
arguments:
- '@flux_se.sylius_stripe.stripe.factory.client'
- '@flux_se.sylius_stripe.provider.web_elements.create.payment_intent_params'
- '@flux_se.sylius_stripe.provider.web_elements.create.params'
FluxSE\SyliusStripePlugin\Manager\WebElements\CreateManagerInterface:
alias: flux_se.sylius_stripe.manager.web_elements.create

Expand Down Expand Up @@ -62,6 +63,6 @@ services:
class: FluxSE\SyliusStripePlugin\Manager\Refund\CreateManager
arguments:
- '@flux_se.sylius_stripe.stripe.factory.client'
- '@flux_se.sylius_stripe.provider.refund.create'
- '@flux_se.sylius_stripe.provider.refund.create.params'
FluxSE\SyliusStripePlugin\Manager\Refund\CreateManagerInterface:
alias: flux_se.sylius_stripe.manager.refund.create
6 changes: 5 additions & 1 deletion src/Manager/Checkout/CreateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
use FluxSE\SyliusStripePlugin\Provider\OptsProviderInterface;
use FluxSE\SyliusStripePlugin\Provider\ParamsProviderInterface;
use FluxSE\SyliusStripePlugin\Stripe\Factory\ClientFactoryInterface;
use Stripe\Checkout\Session;
use Stripe\Service\Checkout\SessionService;

final class CreateManager implements CreateManagerInterface
{
use CheckoutSessionServiceAwareTrait;

/** @use CreateManagerTrait<SessionService> */
/** @use CreateManagerTrait<SessionService, Session> */
use CreateManagerTrait;

/**
* @param ParamsProviderInterface<Session> $paramsProvider
*/
public function __construct(
ClientFactoryInterface $stripeClientFactory,
ParamsProviderInterface $paramsProvider,
Expand Down
3 changes: 3 additions & 0 deletions src/Manager/Checkout/ExpireManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ final class ExpireManager implements ExpireManagerInterface
/** @use StripeClientAwareManagerTrait<SessionService> */
use StripeClientAwareManagerTrait;

/**
* @param ParamsProviderInterface<Session>|null $paramsProvider
*/
public function __construct(
ClientFactoryInterface $stripeClientFactory,
private ?ParamsProviderInterface $paramsProvider = null,
Expand Down
6 changes: 5 additions & 1 deletion src/Manager/Checkout/RetrieveManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
use FluxSE\SyliusStripePlugin\Provider\OptsProviderInterface;
use FluxSE\SyliusStripePlugin\Provider\ParamsProviderInterface;
use FluxSE\SyliusStripePlugin\Stripe\Factory\ClientFactoryInterface;
use Stripe\Checkout\Session;
use Stripe\Service\Checkout\SessionService;

final class RetrieveManager implements RetrieveManagerInterface
{
use CheckoutSessionServiceAwareTrait;

/** @use RetrieveManagerTrait<SessionService> */
/** @use RetrieveManagerTrait<SessionService, Session> */
use RetrieveManagerTrait;

/**
* @param ParamsProviderInterface<Session>|null $paramsProvider
*/
public function __construct(
ClientFactoryInterface $stripeClientFactory,
?ParamsProviderInterface $paramsProvider = null,
Expand Down
4 changes: 4 additions & 0 deletions src/Manager/CreateManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@

/**
* @template T as AbstractService
* @template O as ApiResource
*/
trait CreateManagerTrait
{
/** @use StripeClientAwareManagerTrait<T> */
use StripeClientAwareManagerTrait;

/**
* @var ParamsProviderInterface<O> $paramsProvider
*/
private readonly ParamsProviderInterface $paramsProvider;

private ?OptsProviderInterface $optsProvider = null;
Expand Down
6 changes: 5 additions & 1 deletion src/Manager/Event/RetrieveManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
use FluxSE\SyliusStripePlugin\Provider\OptsProviderInterface;
use FluxSE\SyliusStripePlugin\Provider\ParamsProviderInterface;
use FluxSE\SyliusStripePlugin\Stripe\Factory\ClientFactoryInterface;
use Stripe\Event;
use Stripe\Service\EventService;

final class RetrieveManager implements RetrieveManagerInterface
{
use EventServiceAwareTrait;

/** @use RetrieveManagerTrait<EventService> */
/** @use RetrieveManagerTrait<EventService, Event> */
use RetrieveManagerTrait;

/**
* @param ParamsProviderInterface<Event>|null $paramsProvider
*/
public function __construct(
ClientFactoryInterface $stripeClientFactory,
?ParamsProviderInterface $paramsProvider = null,
Expand Down
6 changes: 5 additions & 1 deletion src/Manager/Refund/CreateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
use FluxSE\SyliusStripePlugin\Provider\OptsProviderInterface;
use FluxSE\SyliusStripePlugin\Provider\ParamsProviderInterface;
use FluxSE\SyliusStripePlugin\Stripe\Factory\ClientFactoryInterface;
use Stripe\Refund;
use Stripe\Service\RefundService;

final class CreateManager implements CreateManagerInterface
{
use RefundServiceAwareTrait;

/** @use CreateManagerTrait<RefundService> */
/** @use CreateManagerTrait<RefundService, Refund> */
use CreateManagerTrait;

/**
* @param ParamsProviderInterface<Refund> $paramsProvider
*/
public function __construct(
ClientFactoryInterface $stripeClientFactory,
ParamsProviderInterface $paramsProvider,
Expand Down
4 changes: 4 additions & 0 deletions src/Manager/RetrieveManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@

/**
* @template T as AbstractService
* @template O as ApiResource
*/
trait RetrieveManagerTrait
{
/** @use StripeClientAwareManagerTrait<T> */
use StripeClientAwareManagerTrait;

/**
* @var ParamsProviderInterface<O>|null $paramsProvider
*/
private ?ParamsProviderInterface $paramsProvider = null;

private ?OptsProviderInterface $optsProvider = null;
Expand Down
3 changes: 3 additions & 0 deletions src/Manager/WebElements/CancelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ final class CancelManager implements CancelManagerInterface
/** @use StripeClientAwareManagerTrait<PaymentIntentService> */
use StripeClientAwareManagerTrait;

/**
* @param ParamsProviderInterface<PaymentIntent>|null $paramsProvider
*/
public function __construct(
ClientFactoryInterface $stripeClientFactory,
private ?ParamsProviderInterface $paramsProvider = null,
Expand Down
3 changes: 3 additions & 0 deletions src/Manager/WebElements/CaptureManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ final class CaptureManager implements CaptureManagerInterface
/** @use StripeClientAwareManagerTrait<PaymentIntentService> */
use StripeClientAwareManagerTrait;

/**
* @param ParamsProviderInterface<PaymentIntent>|null $paramsProvider
*/
public function __construct(
ClientFactoryInterface $stripeClientFactory,
private ?ParamsProviderInterface $paramsProvider = null,
Expand Down
6 changes: 5 additions & 1 deletion src/Manager/WebElements/CreateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
use FluxSE\SyliusStripePlugin\Provider\OptsProviderInterface;
use FluxSE\SyliusStripePlugin\Provider\ParamsProviderInterface;
use FluxSE\SyliusStripePlugin\Stripe\Factory\ClientFactoryInterface;
use Stripe\PaymentIntent;
use Stripe\Service\PaymentIntentService;

final class CreateManager implements CreateManagerInterface
{
use PaymentIntentServiceAwareTrait;

/** @use CreateManagerTrait<PaymentIntentService> */
/** @use CreateManagerTrait<PaymentIntentService, PaymentIntent> */
use CreateManagerTrait;

/**
* @param ParamsProviderInterface<PaymentIntent> $paramsProvider
*/
public function __construct(
ClientFactoryInterface $stripeClientFactory,
ParamsProviderInterface $paramsProvider,
Expand Down
6 changes: 5 additions & 1 deletion src/Manager/WebElements/RetrieveManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
use FluxSE\SyliusStripePlugin\Provider\OptsProviderInterface;
use FluxSE\SyliusStripePlugin\Provider\ParamsProviderInterface;
use FluxSE\SyliusStripePlugin\Stripe\Factory\ClientFactoryInterface;
use Stripe\PaymentIntent;
use Stripe\Service\PaymentIntentService;

final class RetrieveManager implements RetrieveManagerInterface
{
use PaymentIntentServiceAwareTrait;

/** @use RetrieveManagerTrait<PaymentIntentService> */
/** @use RetrieveManagerTrait<PaymentIntentService, PaymentIntent> */
use RetrieveManagerTrait;

/**
* @param ParamsProviderInterface<PaymentIntent>|null $paramsProvider
*/
public function __construct(
ClientFactoryInterface $stripeClientFactory,
?ParamsProviderInterface $paramsProvider = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class CheckoutSessionCreatePayloadRequirementValidator extends ConstraintV
/**
* @param string[] $supportedFactoryNames
* @param string[] $supportedActions
* @param PaymentMethodRepositoryInterface<PaymentMethodInterface> $paymentMethodRepository
*/
public function __construct(
private PaymentMethodRepositoryInterface $paymentMethodRepository,
Expand All @@ -28,10 +29,8 @@ public function __construct(

public function validate(mixed $value, Constraint $constraint): void
{
/** @var CheckoutSessionCreatePayloadRequirement $constraint */
Assert::isInstanceOf($constraint, CheckoutSessionCreatePayloadRequirement::class);

/** @var AddPaymentRequest $addPaymentRequest */
$addPaymentRequest = $this->context->getObject();
Assert::isInstanceOf($addPaymentRequest, AddPaymentRequest::class);

Expand Down Expand Up @@ -60,6 +59,10 @@ public function validate(mixed $value, Constraint $constraint): void
return;
}

if (false === is_array($value)) {
return;
}

if (false === isset($value['success_url'])) {
$this->context->addViolation($constraint->noSuccessUrlFound);
}
Expand Down
1 change: 0 additions & 1 deletion tests/Behat/Context/Setup/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ public function iAmPreparedToRefundThisOrder(): void
*/
public function iAmPreparedToCaptureAuthorizationOfThisOrder(OrderInterface $order): void
{
/** @var PaymentInterface $payment */
$details = $this->getLastNewPaymentDetails($order);
$status = $details['status'] ?? PaymentIntent::STATUS_REQUIRES_CAPTURE;
$captureMethod = $details['capture_method'] ?? PaymentIntent::CAPTURE_METHOD_MANUAL;
Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/Checkout/Create/DetailsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp(): void
$this->loader = static::getContainer()->get('fidry_alice_data_fixtures.loader.doctrine');
$this->entityManager = static::getContainer()->get('doctrine.orm.entity_manager');

$this->compositeParamsProvider = static::getContainer()->get('flux_se.sylius_stripe.provider.checkout.create.checkout_session_params');
$this->compositeParamsProvider = static::getContainer()->get('flux_se.sylius_stripe.provider.checkout.create.params');

$this->requestContext = static::getContainer()->get('router.request_context');

Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/WebElements/Create/DetailsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void
$this->loader = static::getContainer()->get('fidry_alice_data_fixtures.loader.doctrine');
$this->entityManager = static::getContainer()->get('doctrine.orm.entity_manager');

$this->compositeParamsProvider = static::getContainer()->get('flux_se.sylius_stripe.provider.web_elements.create.payment_intent_params');
$this->compositeParamsProvider = static::getContainer()->get('flux_se.sylius_stripe.provider.web_elements.create.params');

$this->purgeDatabase();
}
Expand Down

0 comments on commit 3ae1523

Please sign in to comment.