Skip to content

Commit

Permalink
Merge pull request #93 from Setono/allow-php74
Browse files Browse the repository at this point in the history
Allow PHP 7.4
  • Loading branch information
loevgaard authored May 19, 2023
2 parents 1f79019 + 3a3491a commit 907a150
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 94 deletions.
26 changes: 7 additions & 19 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1" # Always use the lowest version of PHP since a higher version could create actual syntax errors in lower versions
- "7.4" # Always use the lowest version of PHP since a higher version could create actual syntax errors in lower versions

dependencies:
- "highest"
Expand Down Expand Up @@ -68,16 +68,13 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.1"
- "8.2"

dependencies:
- "highest"

symfony:
- "^5.4"
- "^6.0"

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
Expand Down Expand Up @@ -111,16 +108,13 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.1"
- "8.2"

dependencies:
- "highest"

symfony:
- "^5.4"
- "^6.0"

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
Expand Down Expand Up @@ -154,16 +148,13 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.1"
- "8.2"

dependencies:
- "highest"

symfony:
- "^5.4"
- "^6.0"

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
Expand Down Expand Up @@ -194,16 +185,13 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.1"
- "8.2"

dependencies:
- "highest"

symfony:
- "^5.4"
- "^6.0"

steps:
- name: "Start MySQL"
run: "sudo /etc/init.d/mysql start"
Expand All @@ -218,7 +206,7 @@ jobs:
extensions: "${{ env.PHP_EXTENSIONS }}"
php-version: "${{ matrix.php-version }}"
tools: "flex"

- name: "Install composer dependencies"
uses: "ramsey/composer-install@v2"
env:
Expand All @@ -237,7 +225,7 @@ jobs:

- name: "Validate Doctrine mapping"
run: "(cd tests/Application && bin/console doctrine:schema:validate)"

code-coverage:
name: "Code Coverage (PHP${{ matrix.php-version }} | Deps: ${{ matrix.dependencies }})"

Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"google"
],
"require": {
"php": ">=8.1",
"php": ">=7.4",
"ext-json": "*",
"doctrine/collections": "^1.8",
"knplabs/knp-menu": "^3.3",
"psr/event-dispatcher": "^1.0",
"psr/log": "^2.0 || ^3.0",
"setono/composite-compiler-pass": "^1.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"setono/composite-compiler-pass": "^1.1",
"setono/google-analytics-bundle": "^1.0@alpha",
"setono/google-analytics-measurement-protocol": "^1.0@alpha",
"sylius/resource-bundle": "^1.8",
Expand All @@ -35,12 +35,13 @@
"behat/behat": "^3.12",
"matthiasnoback/symfony-config-test": "^4.3",
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
"php-http/message-factory": "^1.1",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^5.0",
"setono/code-quality-pack": "^2.4",
"sylius/sylius": "~1.12.3",
"sylius/sylius": "~1.10.14",
"symfony/debug-bundle": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/intl": "^5.4 || ^6.0",
Expand Down
14 changes: 8 additions & 6 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;

return static function (ECSConfig $config): void {
return static function (ContainerConfigurator $config): void {
$config->import('vendor/sylius-labs/coding-standard/ecs.php');
$config->paths([
'src', 'tests'
$config->parameters()->set(Option::PATHS, [
'src',
'tests'
]);
$config->skip([
'tests/Application/**'
$config->parameters()->set(Option::SKIP, [
'tests/Application/**'
]);
};
21 changes: 21 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->sets([
DowngradeLevelSetList::DOWN_TO_PHP_74
]);
$rectorConfig->skip([
'tests/Application/**'
]);
};
21 changes: 15 additions & 6 deletions src/Event/ItemListViewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@
*/
final class ItemListViewed
{
public function __construct(
public string $listId,
public string $listName,
/** @var list<ProductInterface> $products */
public array $products,
) {
public string $listId;

public string $listName;

/** @var list<ProductInterface> */
public array $products;

/**
* @param list<ProductInterface> $products
*/
public function __construct(string $listId, string $listName, array $products)
{
$this->listId = $listId;
$this->listName = $listName;
$this->products = $products;
}

/**
Expand Down
17 changes: 12 additions & 5 deletions src/Event/ItemResolved.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@
*/
final class ItemResolved
{
public function __construct(
public Item $item,
/** @var array<string, mixed> $context */
public array $context = [],
) {
public Item $item;

/** @var array<string, mixed> */
public array $context = [];

/**
* @param array<string, mixed> $context
*/
public function __construct(Item $item, array $context = [])
{
$this->item = $item;
$this->context = $context;
}
}
22 changes: 16 additions & 6 deletions src/EventSubscriber/AddPaymentInfoSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ final class AddPaymentInfoSubscriber implements EventSubscriberInterface, Logger

private LoggerInterface $logger;

public function __construct(
private readonly EventDispatcherInterface $eventDispatcher,
private readonly ItemsResolverInterface $itemsResolver,
) {
private EventDispatcherInterface $eventDispatcher;

private ItemsResolverInterface $itemsResolver;

public function __construct(EventDispatcherInterface $eventDispatcher, ItemsResolverInterface $itemsResolver)
{
$this->logger = new NullLogger();
$this->eventDispatcher = $eventDispatcher;
$this->itemsResolver = $itemsResolver;
}

public static function getSubscribedEvents(): array
Expand All @@ -44,15 +48,21 @@ public function track(ResourceControllerEvent $resourceControllerEvent): void
$order = $resourceControllerEvent->getSubject();
Assert::isInstanceOf($order, OrderInterface::class);

$paymentMethod = $order->getLastPayment()?->getMethod()?->getCode();
$lastPayment = $order->getLastPayment();
Assert::notNull($lastPayment);

$paymentMethod = $lastPayment->getMethod();
Assert::notNull($paymentMethod);

$paymentMethodCode = $paymentMethod->getCode();
Assert::notNull($paymentMethodCode);

$this->eventDispatcher->dispatch(
new ClientSideEvent(
AddPaymentInfoEvent::create()
->setValue(self::formatAmount($order->getTotal()))
->setCurrency($order->getCurrencyCode())
->setPaymentType($paymentMethod)
->setPaymentType($paymentMethodCode)
->setItems($this->itemsResolver->resolveFromOrder($order)),
),
);
Expand Down
25 changes: 17 additions & 8 deletions src/EventSubscriber/AddShippingInfoSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ final class AddShippingInfoSubscriber implements EventSubscriberInterface, Logge

private LoggerInterface $logger;

public function __construct(
private readonly EventDispatcherInterface $eventDispatcher,
private readonly ItemsResolverInterface $itemsResolver,
) {
private EventDispatcherInterface $eventDispatcher;

private ItemsResolverInterface $itemsResolver;

public function __construct(EventDispatcherInterface $eventDispatcher, ItemsResolverInterface $itemsResolver)
{
$this->logger = new NullLogger();
$this->eventDispatcher = $eventDispatcher;
$this->itemsResolver = $itemsResolver;
}

public static function getSubscribedEvents(): array
Expand All @@ -44,18 +48,23 @@ public function track(ResourceControllerEvent $resourceControllerEvent): void
$order = $resourceControllerEvent->getSubject();
Assert::isInstanceOf($order, OrderInterface::class);

$shippingMethod = null;
$shippingMethodCode = null;
foreach ($order->getShipments() as $shipment) {
$shippingMethod = $shipment->getMethod()?->getCode();
$shippingMethod = $shipment->getMethod();
if (null === $shippingMethod) {
continue;
}

$shippingMethodCode = $shippingMethod->getCode();
}
Assert::notNull($shippingMethod);
Assert::notNull($shippingMethodCode);

$this->eventDispatcher->dispatch(
new ClientSideEvent(
AddShippingInfoEvent::create()
->setValue(self::formatAmount($order->getTotal()))
->setCurrency($order->getCurrencyCode())
->setShippingTier($shippingMethod)
->setShippingTier($shippingMethodCode)
->setItems($this->itemsResolver->resolveFromOrder($order)),
),
);
Expand Down
15 changes: 12 additions & 3 deletions src/EventSubscriber/AddToCartSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@ final class AddToCartSubscriber implements EventSubscriberInterface, LoggerAware

private LoggerInterface $logger;

private EventDispatcherInterface $eventDispatcher;

private CartContextInterface $cartContext;

private ItemResolverInterface $itemResolver;

public function __construct(
private readonly EventDispatcherInterface $eventDispatcher,
private readonly CartContextInterface $cartContext,
private readonly ItemResolverInterface $itemResolver,
EventDispatcherInterface $eventDispatcher,
CartContextInterface $cartContext,
ItemResolverInterface $itemResolver
) {
$this->logger = new NullLogger();
$this->eventDispatcher = $eventDispatcher;
$this->cartContext = $cartContext;
$this->itemResolver = $itemResolver;
}

public static function getSubscribedEvents(): array
Expand Down
15 changes: 12 additions & 3 deletions src/EventSubscriber/BeginCheckoutSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@ final class BeginCheckoutSubscriber implements EventSubscriberInterface, LoggerA

private LoggerInterface $logger;

private EventDispatcherInterface $eventDispatcher;

private CartContextInterface $cartContext;

private ItemsResolverInterface $itemsResolver;

public function __construct(
private readonly EventDispatcherInterface $eventDispatcher,
private readonly CartContextInterface $cartContext,
private readonly ItemsResolverInterface $itemsResolver,
EventDispatcherInterface $eventDispatcher,
CartContextInterface $cartContext,
ItemsResolverInterface $itemsResolver
) {
$this->logger = new NullLogger();
$this->eventDispatcher = $eventDispatcher;
$this->cartContext = $cartContext;
$this->itemsResolver = $itemsResolver;
}

public static function getSubscribedEvents(): array
Expand Down
15 changes: 12 additions & 3 deletions src/EventSubscriber/PurchaseSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@ final class PurchaseSubscriber implements EventSubscriberInterface, LoggerAwareI

private LoggerInterface $logger;

private EventDispatcherInterface $eventDispatcher;

private OrderRepositoryInterface $orderRepository;

private ItemsResolverInterface $itemsResolver;

public function __construct(
private readonly EventDispatcherInterface $eventDispatcher,
private readonly OrderRepositoryInterface $orderRepository,
private readonly ItemsResolverInterface $itemsResolver,
EventDispatcherInterface $eventDispatcher,
OrderRepositoryInterface $orderRepository,
ItemsResolverInterface $itemsResolver
) {
$this->logger = new NullLogger();
$this->eventDispatcher = $eventDispatcher;
$this->orderRepository = $orderRepository;
$this->itemsResolver = $itemsResolver;
}

public static function getSubscribedEvents(): array
Expand Down
Loading

0 comments on commit 907a150

Please sign in to comment.