Skip to content

Commit

Permalink
Fix static checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Apr 26, 2023
1 parent 736841a commit 547bdd3
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 21 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"require": {
"php": "^8.0",
"sylius/sylius": "^1.12",
"sylius/mailer-bundle": "^1.8 || ^2.0",
"sylius/mailer-bundle": "^1.8 || ^2.0",
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/webpack-encore-bundle": "^1.15"
},
"require-dev": {
Expand Down
1 change: 0 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
VisibilityRequiredFixer::class => ['*Spec.php'],
]);
};

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
use Sylius\CustomerReorderPlugin\ReorderEligibility\ResponseProcessing\EligibilityCheckerFailureResponses;
use Sylius\CustomerReorderPlugin\ReorderEligibility\ResponseProcessing\ReorderEligibilityCheckerResponseProcessor;
use Sylius\CustomerReorderPlugin\ReorderEligibility\ResponseProcessing\ReorderEligibilityCheckerResponseProcessorInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\Session;

final class ReorderEligibilityCheckerResponseProcessorSpec extends ObjectBehavior
{
public function let(Session $session): void
public function let(RequestStack $requestStack): void
{
$this->beConstructedWith($session);
$this->beConstructedWith($requestStack);
}

public function it_is_initializable(): void
Expand All @@ -33,6 +34,7 @@ public function it_adds_flash_bag_messages_based_on_given_array(
ReorderEligibilityCheckerResponse $firstResponse,
ReorderEligibilityCheckerResponse $secondResponse,
ReorderEligibilityCheckerResponse $thirdResponse,
RequestStack $requestStack,
Session $session,
FlashBagInterface $flashBag,
): void {
Expand All @@ -45,6 +47,7 @@ public function it_adds_flash_bag_messages_based_on_given_array(
$thirdResponse->getMessage()->willReturn(EligibilityCheckerFailureResponses::TOTAL_AMOUNT_CHANGED);
$thirdResponse->getParameters()->willReturn(['%order_total%' => '$100.00']);

$requestStack->getSession()->willReturn($session);
$session->getFlashBag()->willReturn($flashBag);

$flashBag->add('info', [
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/CustomerReorderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

final class CustomerReorderAction
Expand Down Expand Up @@ -46,7 +47,10 @@ public function __invoke(Request $request): Response
try {
$reorder = $this->reorderer->reorder($order, $channel, $customer);
} catch (InvalidArgumentException $exception) {
$this->requestStack->getSession()->getFlashBag()->add('info', $exception->getMessage());
$session = $this->requestStack->getSession();
if ($session instanceof Session) {
$session->getFlashBag()->add('info', $exception->getMessage());
}

return new RedirectResponse($this->urlGenerator->generate('sylius_shop_account_order_index'));
}
Expand Down
4 changes: 3 additions & 1 deletion src/Factory/OrderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

final class OrderFactory implements OrderFactoryInterface
{
/**
* @param FactoryInterface<OrderInterface> $baseOrderFactory
*/
public function __construct(private FactoryInterface $baseOrderFactory, private ReorderProcessor $reorderProcessor)
{
}

public function createFromExistingOrder(OrderInterface $order, ChannelInterface $channel): OrderInterface
{
$reorder = $this->baseOrderFactory->createNew();
assert($reorder instanceof OrderInterface);

$reorder->setChannel($channel);
$this->reorderProcessor->process($order, $reorder);
Expand Down
3 changes: 2 additions & 1 deletion src/ReorderEligibility/ItemsOutOfStockEligibilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(

public function check(OrderInterface $order, OrderInterface $reorder): array
{
/** @var string[] $productsOutOfStock */
$productsOutOfStock = [];

foreach ($order->getItems()->getValues() as $orderItem) {
Expand All @@ -29,7 +30,7 @@ public function check(OrderInterface $order, OrderInterface $reorder): array
/** @var ProductVariantInterface $productVariant */
$productVariant = $orderItem->getVariant();
if (!$this->availabilityChecker->isStockAvailable($productVariant)) {
$productsOutOfStock[] = $orderItem->getProductName();
$productsOutOfStock[] = (string) $orderItem->getProductName();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ public function format(array $messageParameters): string
$message = '';

if (count($messageParameters) === 1) {
/** @var string $message */
$message = array_pop($messageParameters);

return $message;
return array_pop($messageParameters);
}

/** @var string $lastMessageParameter */
$lastMessageParameter = end($messageParameters);
/** @var string $messageParameter */
foreach ($messageParameters as $messageParameter) {
$message .= $messageParameter . (($messageParameter !== $lastMessageParameter) ? ', ' : '');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

interface ReorderEligibilityConstraintMessageFormatterInterface
{
/** @var string[] $messageParameters */
/** @param string[] $messageParameters */
public function format(array $messageParameters): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public function check(OrderInterface $order, OrderInterface $reorder): array
return [];
}

/** @var string[] $disabledPromotions */
$disabledPromotions = [];

/** @var PromotionInterface $promotion */
foreach ($order->getPromotions()->getValues() as $promotion) {
if (!in_array($promotion, $reorder->getPromotions()->getValues(), true)) {
$disabledPromotions[] = $promotion->getName();
$disabledPromotions[] = (string) $promotion->getName();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ public function process(array $responses): void
{
/** @var ReorderEligibilityCheckerResponse $response */
foreach ($responses as $response) {
$this->requestStack->getSession()->getFlashBag()->add('info', [
'message' => $response->getMessage(),
'parameters' => $response->getParameters(),
]);
$session = $this->requestStack->getSession();
if ($session instanceof Session) {
$session->getFlashBag()->add('info', [
'message' => $response->getMessage(),
'parameters' => $response->getParameters(),
]);
}
}
}
}
5 changes: 3 additions & 2 deletions src/ReorderProcessing/ReorderItemsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

final class ReorderItemsProcessor implements ReorderProcessor
{
/**
* @param FactoryInterface<OrderItemInterface> $orderItemFactory
*/
public function __construct(
private OrderItemQuantityModifierInterface $orderItemQuantityModifier,
private OrderModifierInterface $orderModifier,
Expand Down Expand Up @@ -42,8 +45,6 @@ public function process(OrderInterface $order, OrderInterface $reorder): void
} else {
$reorderItemQuantity = $orderItem->getQuantity();
}

/** @var OrderItemInterface $newItem */
$newItem = $this->orderItemFactory->createNew();

$newItem->setVariant($productVariant);
Expand Down

0 comments on commit 547bdd3

Please sign in to comment.