From cee588f04ba2f7017fb3c804bf0aa3328ee4f5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Tue, 15 Mar 2022 13:58:19 +0100 Subject: [PATCH 1/3] Testing with PHP 8.1 --- .github/workflows/build.yml | 8 ++++++-- composer.json | 2 +- src/Component/composer.json | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 60e5c7b5b..1215db76c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,11 +26,15 @@ jobs: - php: 8.0 symfony: ^4.4 - composer-flags: --ignore-platform-req=php - php: 8.0 symfony: ^5.2 - composer-flags: --ignore-platform-req=php + - + php: 8.1 + symfony: ^4.4 + - + php: 8.1 + symfony: ^5.2 - php: 7.4 symfony: ^4.4 diff --git a/composer.json b/composer.json index 206e13627..90382c821 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "lchrusciel/api-test-case": "^5.0", "matthiasnoback/symfony-dependency-injection-test": "^4.2.1", "pamil/phpspec-skip-example-extension": "^4.2", - "phpspec/phpspec": "^7.0", + "phpspec/phpspec": "^7.2", "phpspec/prophecy-phpunit": "^2.0", "phpstan/phpstan": "0.12.83", "phpstan/phpstan-phpunit": "0.12.18", diff --git a/src/Component/composer.json b/src/Component/composer.json index 824be5cf8..c8b449532 100644 --- a/src/Component/composer.json +++ b/src/Component/composer.json @@ -38,7 +38,7 @@ }, "require-dev": { "behat/transliterator": "^1.3", - "phpspec/phpspec": "^7.0", + "phpspec/phpspec": "^7.2", "phpunit/phpunit": "^9.5" }, "extra": { From e2187f6a7b1cf72901911f2d42b676ee5336bc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Tue, 15 Mar 2022 14:12:43 +0100 Subject: [PATCH 2/3] Fix PHPStan errors --- src/Bundle/Controller/ResourceController.php | 4 ++-- src/Bundle/EventListener/ORMRepositoryClassSubscriber.php | 3 ++- .../HttpFoundation/HttpFoundationRequestHandler.php | 8 +++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Bundle/Controller/ResourceController.php b/src/Bundle/Controller/ResourceController.php index 63e0256fe..713c705f4 100644 --- a/src/Bundle/Controller/ResourceController.php +++ b/src/Bundle/Controller/ResourceController.php @@ -335,7 +335,7 @@ public function deleteAction(Request $request): Response $this->isGrantedOr403($configuration, ResourceActions::DELETE); $resource = $this->findOr404($configuration); - if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid((string) $resource->getId(), $request->request->get('_csrf_token'))) { + if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid((string) $resource->getId(), (string) $request->request->get('_csrf_token'))) { throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.'); } @@ -394,7 +394,7 @@ public function bulkDeleteAction(Request $request): Response if ( $configuration->isCsrfProtectionEnabled() && - !$this->isCsrfTokenValid(ResourceActions::BULK_DELETE, $request->request->get('_csrf_token')) + !$this->isCsrfTokenValid(ResourceActions::BULK_DELETE, (string) $request->request->get('_csrf_token')) ) { throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.'); } diff --git a/src/Bundle/EventListener/ORMRepositoryClassSubscriber.php b/src/Bundle/EventListener/ORMRepositoryClassSubscriber.php index bc9cc6fda..6b8fad52b 100644 --- a/src/Bundle/EventListener/ORMRepositoryClassSubscriber.php +++ b/src/Bundle/EventListener/ORMRepositoryClassSubscriber.php @@ -13,6 +13,7 @@ namespace Sylius\Bundle\ResourceBundle\EventListener; +use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Event\LoadClassMetadataEventArgs; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadata; @@ -40,7 +41,7 @@ private function setCustomRepositoryClass(ClassMetadata $metadata): void } if ($resourceMetadata->hasClass('repository')) { - /** @psalm-var class-string $repository */ + /** @psalm-var class-string|null $repository */ $repository = $resourceMetadata->getClass('repository'); $metadata->setCustomRepositoryClass($repository); } diff --git a/src/Bundle/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php b/src/Bundle/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php index 89ebfd67d..ddc334416 100644 --- a/src/Bundle/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php +++ b/src/Bundle/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php @@ -85,7 +85,13 @@ public function handleRequest(FormInterface $form, $request = null) } elseif ($request->request->has($name) || $request->files->has($name)) { /** @psalm-var array|null $default */ $default = $form->getConfig()->getCompound() ? [] : null; - $params = $request->request->get($name, $default); + + if ($request->request->has($name)) { + $params = $request->request->get($name); + } else { + $params = $default; + } + $files = $request->files->get($name, $default); } else { // Don't submit the form if it is not present in the request From e4b613c3f2d7e9df3cdb21615df58018c86360b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Tue, 15 Mar 2022 14:22:30 +0100 Subject: [PATCH 3/3] Fix PHPStan errors with PHP 8.1 --- composer.json | 2 +- .../Form/DataTransformer/CollectionToStringTransformer.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 90382c821..d3638eed0 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ "pamil/phpspec-skip-example-extension": "^4.2", "phpspec/phpspec": "^7.2", "phpspec/prophecy-phpunit": "^2.0", - "phpstan/phpstan": "0.12.83", + "phpstan/phpstan": "0.12.96", "phpstan/phpstan-phpunit": "0.12.18", "phpstan/phpstan-webmozart-assert": "0.12.12", "phpunit/phpunit": "^9.5", diff --git a/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php b/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php index b7cebd3c2..b6b688b74 100644 --- a/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php +++ b/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php @@ -62,6 +62,7 @@ public function reverseTransform($value): Collection return new ArrayCollection(); } - return new ArrayCollection(explode($this->delimiter, $value) ?: []); + /** Explode would return string[]|false for PHP 7.4 and string[] for PHP 8 which messes in PHPStan algorithms */ + return new ArrayCollection(explode($this->delimiter, $value) ?: []); // @phpstan-ignore-line } }