Skip to content

Commit

Permalink
feature #386 Add Symfony 6 support (coldic3, GSadee)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.3 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.3
| Bug fix?        | no
| New feature?    | no
| Related tickets | 

To be merged on Sylius 1.12 release 💃

In addition, #385 should be merged before this one then the rebase will be needed.

Commits
-------

124da5b [GitHub Actions] Add Sylius 1.12 to the matrix
69d029f [Maintenance] Add support for Symfony 6
abf9148 [Maintenance] Fix Kernel.php and app configs
5483b16 [Maintenance] Adjust services to Sylius 6
006c863 [Maintenance] Fix deprecated services definitions
726ccf1 [Maintenance] Upgrade PHPStan packages
6ca616b [GitHub Actions] Bump node version
e79164a Add missing deprecation
fb14324 [GitHub Actions] Add more elements to the matrix
  • Loading branch information
GSadee authored Nov 8, 2022
2 parents d5efc4a + fb14324 commit 09ef1e6
Show file tree
Hide file tree
Showing 28 changed files with 209 additions and 180 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ jobs:
fail-fast: false
matrix:
php: ["8.0", "8.1"]
symfony: ["^5.4"]
sylius: ["~1.11.2", "~1.12.0"]
node: ["14.x"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.11.4", "~1.12.0"]
node: ["16.x"]
mysql: ["5.7", "8.0"]
pdf: [true]

include:
-
php: "8.1"
symfony: "^6.0"
sylius: "~1.12.0"
node: "16.x"
mysql: "8.0"
pdf: false
-
php: "8.1"
symfony: "^5.4"
Expand All @@ -35,6 +42,10 @@ jobs:
mysql: "8.0"
pdf: false

exclude:
- symfony: "^6.0"
sylius: "~1.11.4"

env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"
Expand Down Expand Up @@ -183,7 +194,7 @@ jobs:

-
name: Run PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon -l max src/
run: vendor/bin/phpstan analyse -c phpstan.neon src/

-
name: Run PHPSpec
Expand Down
24 changes: 14 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"myclabs/php-enum": "^1.7",
"sylius/resource-bundle": "^1.6",
"sylius/sylius": "~1.11.4 || ~1.12.0",
"symfony/messenger": "^5.4"
"symfony/messenger": "^5.4 || ^6.0"
},
"require-dev": {
"behat/behat": "^3.6",
Expand All @@ -40,20 +40,19 @@
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"friendsofsymfony/oauth-server-bundle": ">2.0.0-alpha.0 ^2.0@dev",
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"phpspec/phpspec": "^7.0",
"phpstan/phpstan": "0.12.96",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpstan/phpstan": "1.5.4",
"phpstan/phpstan-webmozart-assert": "1.1.2",
"phpunit/phpunit": "^9.5",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"sylius-labs/coding-standard": "~4.0.0",
"symfony/browser-kit": "^5.4",
"symfony/debug-bundle": "^5.4",
"symfony/dotenv": "^5.4",
"symfony/intl": "^5.4",
"symfony/web-profiler-bundle": "^5.4",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/debug-bundle": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/intl": "^5.4 || ^6.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"symfony/webpack-encore-bundle": "^1.15",
"symplify/easy-coding-standard": "9.3.26"
},
Expand Down Expand Up @@ -88,6 +87,11 @@
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"symfony": {
"require": "^5.4 || ^6.0"
}
}
},
"prefer-stable": true,
"minimum-stability": "dev"
}
13 changes: 8 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ includes:
- vendor/phpstan/phpstan-webmozart-assert/extension.neon

parameters:
level: 8

checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

Expand All @@ -14,8 +16,9 @@ parameters:
- 'tests/Application/src/**.php'

ignoreErrors:
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::id\(\) has no return typehint specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::getId\(\) has no return typehint specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::setId\(\) has parameter \$id with no typehint specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingDataInterface::id\(\) has no return typehint specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingDataInterface::setId\(\) has parameter \$id with no typehint specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::id\(\) has no return type specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::getId\(\) has no return type specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::setId\(\) has parameter \$id with no type specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingDataInterface::id\(\) has no return type specified./'
- '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingDataInterface::setId\(\) has parameter \$id with no type specified./'
- '/Method Sylius\\RefundPlugin\\[a-zA-Z\\]+::getFlashBag\(\) should return Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface but returns Symfony\\Component\\HttpFoundation\\Session\\SessionBagInterface\./'
48 changes: 22 additions & 26 deletions src/Action/Admin/OrderRefundsListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,27 @@
use Sylius\RefundPlugin\Provider\RefundPaymentMethodsProviderInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
use Webmozart\Assert\Assert;

final class OrderRefundsListAction
{
private OrderRepositoryInterface $orderRepository;

private OrderRefundingAvailabilityCheckerInterface $orderRefundsListAvailabilityChecker;

private RefundPaymentMethodsProviderInterface $refundPaymentMethodsProvider;

private Environment $twig;

private Session $session;

private UrlGeneratorInterface $router;

public function __construct(
OrderRepositoryInterface $orderRepository,
OrderRefundingAvailabilityCheckerInterface $orderRefundsListAvailabilityChecker,
RefundPaymentMethodsProviderInterface $refundPaymentMethodsProvider,
Environment $twig,
Session $session,
UrlGeneratorInterface $router
private OrderRepositoryInterface $orderRepository,
private OrderRefundingAvailabilityCheckerInterface $orderRefundsListAvailabilityChecker,
private RefundPaymentMethodsProviderInterface $refundPaymentMethodsProvider,
private Environment $twig,
private SessionInterface | RequestStack $requestStackOrSession,
private UrlGeneratorInterface $router,
) {
$this->orderRepository = $orderRepository;
$this->orderRefundsListAvailabilityChecker = $orderRefundsListAvailabilityChecker;
$this->refundPaymentMethodsProvider = $refundPaymentMethodsProvider;
$this->twig = $twig;
$this->session = $session;
$this->router = $router;
if ($this->requestStackOrSession instanceof SessionInterface) {
trigger_deprecation('sylius/refund-plugin', '1.3', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of Sylius Refund Plugin 1.3 and will be removed in 2.0. Pass an instance of %s instead.', SessionInterface::class, self::class, RequestStack::class));
}
}

public function __invoke(Request $request): Response
Expand Down Expand Up @@ -83,8 +70,17 @@ public function __invoke(Request $request): Response

private function redirectToReferer(OrderInterface $order, string $message): Response
{
$this->session->getFlashBag()->add('error', $message);
$this->getFlashBag()->add('error', $message);

return new RedirectResponse($this->router->generate('sylius_admin_order_show', ['id' => $order->getId()]));
}

private function getFlashBag(): FlashBagInterface
{
if ($this->requestStackOrSession instanceof RequestStack) {
return $this->requestStackOrSession->getSession()->getBag('flashes');
}

return $this->requestStackOrSession->getBag('flashes');
}
}
49 changes: 24 additions & 25 deletions src/Action/Admin/RefundUnitsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,36 @@
use Sylius\RefundPlugin\Exception\InvalidRefundAmount;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

final class RefundUnitsAction
{
private MessageBusInterface $commandBus;

private Session $session;

private UrlGeneratorInterface $router;

private RefundUnitsCommandCreatorInterface $commandCreator;

private LoggerInterface $logger;

public function __construct(
MessageBusInterface $commandBus,
Session $session,
UrlGeneratorInterface $router,
RefundUnitsCommandCreatorInterface $commandCreator,
LoggerInterface $logger
private MessageBusInterface $commandBus,
private SessionInterface | RequestStack $requestStackOrSession,
private UrlGeneratorInterface $router,
private RefundUnitsCommandCreatorInterface $commandCreator,
private LoggerInterface $logger
) {
$this->commandBus = $commandBus;
$this->session = $session;
$this->router = $router;
$this->commandCreator = $commandCreator;
$this->logger = $logger;
if ($this->requestStackOrSession instanceof SessionInterface) {
trigger_deprecation('sylius/refund-plugin', '1.3', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of Sylius Refund Plugin 1.3 and will be removed in 2.0. Pass an instance of %s instead.', SessionInterface::class, self::class, RequestStack::class));
}
}

public function __invoke(Request $request): Response
{
try {
$this->commandBus->dispatch($this->commandCreator->fromRequest($request));

$this->session->getFlashBag()->add('success', 'sylius_refund.units_successfully_refunded');
$this->getFlashBag()->add('success', 'sylius_refund.units_successfully_refunded');
} catch (InvalidRefundAmount $exception) {
$this->session->getFlashBag()->add('error', $exception->getMessage());
$this->getFlashBag()->add('error', $exception->getMessage());

$this->logger->error($exception->getMessage());
} catch (HandlerFailedException $exception) {
Expand All @@ -78,11 +68,20 @@ public function __invoke(Request $request): Response
private function provideErrorMessage(\Throwable $previousException): void
{
if ($previousException instanceof InvalidRefundAmount) {
$this->session->getFlashBag()->add('error', $previousException->getMessage());
$this->getFlashBag()->add('error', $previousException->getMessage());

return;
}

$this->session->getFlashBag()->add('error', 'sylius_refund.error_occurred');
$this->getFlashBag()->add('error', 'sylius_refund.error_occurred');
}

private function getFlashBag(): FlashBagInterface
{
if ($this->requestStackOrSession instanceof RequestStack) {
return $this->requestStackOrSession->getSession()->getBag('flashes');
}

return $this->requestStackOrSession->getBag('flashes');
}
}
38 changes: 20 additions & 18 deletions src/Action/Admin/SendCreditMemoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,25 @@
use Sylius\RefundPlugin\Entity\CreditMemoInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Webmozart\Assert\Assert;

final class SendCreditMemoAction
{
private MessageBusInterface $commandBus;

private RepositoryInterface $creditMemoRepository;

private Session $session;

private UrlGeneratorInterface $router;

public function __construct(
MessageBusInterface $commandBus,
RepositoryInterface $creditMemoRepository,
Session $session,
UrlGeneratorInterface $router
private MessageBusInterface $commandBus,
private RepositoryInterface $creditMemoRepository,
private SessionInterface | RequestStack $requestStackOrSession,
private UrlGeneratorInterface $router
) {
$this->commandBus = $commandBus;
$this->creditMemoRepository = $creditMemoRepository;
$this->session = $session;
$this->router = $router;
if ($this->requestStackOrSession instanceof SessionInterface) {
trigger_deprecation('sylius/refund-plugin', '1.3', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of Sylius Refund Plugin 1.3 and will be removed in 2.0. Pass an instance of %s instead.', SessionInterface::class, self::class, RequestStack::class));
}
}

public function __invoke(Request $request): Response
Expand All @@ -65,8 +58,17 @@ public function __invoke(Request $request): Response

public function addFlashAndRedirect(string $flashType, string $message): RedirectResponse
{
$this->session->getFlashBag()->add($flashType, $message);
$this->getFlashBag()->add($flashType, $message);

return new RedirectResponse($this->router->generate('sylius_refund_admin_credit_memo_index'));
}

private function getFlashBag(): FlashBagInterface
{
if ($this->requestStackOrSession instanceof RequestStack) {
return $this->requestStackOrSession->getSession()->getBag('flashes');
}

return $this->requestStackOrSession->getBag('flashes');
}
}
Loading

0 comments on commit 09ef1e6

Please sign in to comment.