From 060701eacefd19ec15173a38166aec8cf81245a6 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Thu, 14 Dec 2023 15:45:47 -0300 Subject: [PATCH] Allow packages from "symfony/*" ^7 (#2430) --- .github/workflows/test.yaml | 5 ++ composer.json | 56 +++++++++---------- src/Admin/BaseMediaAdmin.php | 4 ++ src/Admin/GalleryAdmin.php | 6 +- src/Controller/GalleryAdminController.php | 2 +- src/Controller/MediaAdminController.php | 11 ++-- src/DependencyInjection/Configuration.php | 40 ++++--------- src/Filesystem/Replicate.php | 2 +- .../ProviderDataTransformer.php | 8 +-- src/Form/Type/MediaType.php | 2 +- ...kwardCompatibleMessageHandlerInterface.php | 32 +++++++++++ src/Messenger/GenerateThumbnailsHandler.php | 7 ++- src/Provider/Metadata.php | 2 +- .../Constraints/ValidMediaFormat.php | 5 +- tests/App/config/config.yaml | 4 +- 15 files changed, 104 insertions(+), 82 deletions(-) create mode 100644 src/Messenger/BackwardCompatibleMessageHandlerInterface.php diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7827f389d..8152cb3ea 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -63,6 +63,11 @@ jobs: allowed-to-fail: false symfony-require: 6.4.* variant: symfony/symfony:"6.4.*" + - php-version: '8.2' + dependencies: highest + allowed-to-fail: false + symfony-require: 7.0.* + variant: symfony/symfony:"7.0.*" steps: - name: Checkout diff --git a/composer.json b/composer.json index 8bf2aa85d..8c72da0d5 100644 --- a/composer.json +++ b/composer.json @@ -38,35 +38,35 @@ "sonata-project/doctrine-extensions": "^1.13 || ^2.0", "sonata-project/form-extensions": "^1.4 || ^2.0", "sonata-project/twig-extensions": "^1.3 || ^2.0", - "symfony/asset": "^5.4 || ^6.2", - "symfony/config": "^5.4 || ^6.2", - "symfony/console": "^5.4 || ^6.2", - "symfony/dependency-injection": "^5.4 || ^6.2", - "symfony/event-dispatcher": "^5.4 || ^6.2", - "symfony/filesystem": "^5.4 || ^6.2", - "symfony/finder": "^5.4 || ^6.2", - "symfony/form": "^5.4 || ^6.2", - "symfony/framework-bundle": "^5.4 || ^6.2", - "symfony/http-client": "^5.4 || ^6.2", - "symfony/http-foundation": "^5.4 || ^6.2", - "symfony/http-kernel": "^5.4 || ^6.2", - "symfony/mime": "^5.4 || ^6.2", - "symfony/options-resolver": "^5.4 || ^6.2", - "symfony/routing": "^5.4 || ^6.2", - "symfony/security-bundle": "^5.4 || ^6.2", - "symfony/security-core": "^5.4 || ^6.2", - "symfony/translation": "^5.4 || ^6.2", + "symfony/asset": "^5.4 || ^6.2 || ^7.0", + "symfony/config": "^5.4 || ^6.2 || ^7.0", + "symfony/console": "^5.4 || ^6.2 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.2 || ^7.0", + "symfony/event-dispatcher": "^5.4 || ^6.2 || ^7.0", + "symfony/filesystem": "^5.4 || ^6.2 || ^7.0", + "symfony/finder": "^5.4 || ^6.2 || ^7.0", + "symfony/form": "^5.4 || ^6.2 || ^7.0", + "symfony/framework-bundle": "^5.4 || ^6.2 || ^7.0", + "symfony/http-client": "^5.4 || ^6.2 || ^7.0", + "symfony/http-foundation": "^5.4 || ^6.2 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.2 || ^7.0", + "symfony/mime": "^5.4 || ^6.2 || ^7.0", + "symfony/options-resolver": "^5.4 || ^6.2 || ^7.0", + "symfony/routing": "^5.4 || ^6.2 || ^7.0", + "symfony/security-bundle": "^5.4 || ^6.2 || ^7.0", + "symfony/security-core": "^5.4 || ^6.2 || ^7.0", + "symfony/translation": "^5.4 || ^6.2 || ^7.0", "symfony/translation-contracts": "^2.0 || ^3.0", - "symfony/twig-bridge": "^5.4 || ^6.2", - "symfony/twig-bundle": "^5.4 || ^6.2", - "symfony/validator": "^5.4 || ^6.2", + "symfony/twig-bridge": "^5.4 || ^6.2 || ^7.0", + "symfony/twig-bundle": "^5.4 || ^6.2 || ^7.0", + "symfony/validator": "^5.4 || ^6.2 || ^7.0", "twig/string-extra": "^3.0", "twig/twig": "^3.0" }, "require-dev": { "async-aws/simple-s3": "^1.0", "aws/aws-sdk-php": "^3.0", - "dama/doctrine-test-bundle": "^7.0", + "dama/doctrine-test-bundle": "^8.0.1", "doctrine/doctrine-bundle": "^2.7", "doctrine/mongodb-odm": "^2.4", "doctrine/orm": "^2.14", @@ -74,8 +74,8 @@ "knplabs/knp-menu-bundle": "^3.0", "liip/imagine-bundle": "^2.0", "masterminds/html5": "^2.7", - "matthiasnoback/symfony-config-test": "^4.2", - "matthiasnoback/symfony-dependency-injection-test": "^4.0", + "matthiasnoback/symfony-config-test": "^4.2 || ^5.1", + "matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1.0", "phpstan/phpstan-phpunit": "^1.0", @@ -89,10 +89,10 @@ "sonata-project/block-bundle": "^4.11 || ^5.0", "sonata-project/classification-bundle": "^4.0", "sonata-project/doctrine-orm-admin-bundle": "^4.0", - "symfony/browser-kit": "^5.4 || ^6.2", - "symfony/messenger": "^5.4 || ^6.2", - "symfony/phpunit-bridge": "^6.2", - "symfony/security-csrf": "^5.4 || ^6.2", + "symfony/browser-kit": "^5.4 || ^6.2 || ^7.0", + "symfony/messenger": "^5.4 || ^6.2 || ^7.0", + "symfony/phpunit-bridge": "^6.2 || ^7.0", + "symfony/security-csrf": "^5.4 || ^6.2 || ^7.0", "vimeo/psalm": "^5.0" }, "conflict": { diff --git a/src/Admin/BaseMediaAdmin.php b/src/Admin/BaseMediaAdmin.php index 151895d2a..eec74d231 100644 --- a/src/Admin/BaseMediaAdmin.php +++ b/src/Admin/BaseMediaAdmin.php @@ -115,6 +115,8 @@ protected function configurePersistentParameters(): array $context = $request->query->get('context', $this->pool->getDefaultContext()); } + \assert(\is_string($context)); + $providers = $this->pool->getProvidersByContext($context); $provider = $request->query->get('provider'); @@ -167,6 +169,8 @@ protected function alterNewInstance(object $object): void $context = $request->query->get('context'); + \assert(null === $context || \is_string($context)); + $object->setProviderName($providerName); $object->setContext($context); diff --git a/src/Admin/GalleryAdmin.php b/src/Admin/GalleryAdmin.php index f4d55bd26..1c1bef45c 100644 --- a/src/Admin/GalleryAdmin.php +++ b/src/Admin/GalleryAdmin.php @@ -64,7 +64,11 @@ protected function alterNewInstance(object $object): void return; } - $object->setContext($this->getRequest()->query->get('context')); + $context = $this->getRequest()->query->get('context'); + + \assert(null === $context || \is_string($context)); + + $object->setContext($context); } protected function configureFormFields(FormMapper $form): void diff --git a/src/Controller/GalleryAdminController.php b/src/Controller/GalleryAdminController.php index f8fb86486..b1f27c1d7 100644 --- a/src/Controller/GalleryAdminController.php +++ b/src/Controller/GalleryAdminController.php @@ -39,7 +39,7 @@ public function listAction(Request $request): Response } $listMode = $request->query->get('_list_mode'); - if (null !== $listMode) { + if (\is_string($listMode)) { $this->admin->setListMode($listMode); } diff --git a/src/Controller/MediaAdminController.php b/src/Controller/MediaAdminController.php index 17208eba6..96a3a4ebc 100644 --- a/src/Controller/MediaAdminController.php +++ b/src/Controller/MediaAdminController.php @@ -43,11 +43,11 @@ public function createAction(Request $request): Response if ($request->isMethod('get') && null === $request->query->get('provider')) { $pool = $this->container->get('sonata.media.pool'); \assert($pool instanceof Pool); + $context = $request->query->get('context', $pool->getDefaultContext()); + \assert(\is_string($context)); return $this->render('@SonataMedia/MediaAdmin/select_provider.html.twig', [ - 'providers' => $pool->getProvidersByContext( - $request->query->get('context', $pool->getDefaultContext()) - ), + 'providers' => $pool->getProvidersByContext($context), 'action' => 'create', ]); } @@ -66,7 +66,10 @@ public function listAction(Request $request): Response return $preResponse; } - $this->admin->setListMode($request->query->get('_list_mode', 'mosaic')); + $listMode = $request->query->get('_list_mode', 'mosaic'); + \assert(\is_string($listMode)); + + $this->admin->setListMode($listMode); $datagrid = $this->admin->getDatagrid(); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 3afbfbb4f..bf02aa687 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -28,9 +28,7 @@ final class Configuration implements ConfigurationInterface private const DB_DRIVERS = ['doctrine_orm', 'doctrine_mongodb', 'no_driver']; /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ public function getConfigTreeBuilder(): TreeBuilder { @@ -86,9 +84,7 @@ public function getConfigTreeBuilder(): TreeBuilder } /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ private function addContextsSection(ArrayNodeDefinition $node): void { @@ -136,9 +132,7 @@ private function addContextsSection(ArrayNodeDefinition $node): void } /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ private function addCdnSection(ArrayNodeDefinition $node): void { @@ -179,9 +173,7 @@ private function addCdnSection(ArrayNodeDefinition $node): void } /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ private function addFilesystemSection(ArrayNodeDefinition $node): void { @@ -273,9 +265,7 @@ private function addFilesystemSection(ArrayNodeDefinition $node): void } /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ private function addProvidersSection(ArrayNodeDefinition $node): void { @@ -401,9 +391,7 @@ private function addProvidersSection(ArrayNodeDefinition $node): void } /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ private function addModelSection(ArrayNodeDefinition $node): void { @@ -422,9 +410,7 @@ private function addModelSection(ArrayNodeDefinition $node): void } /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ private function addHttpClientSection(ArrayNodeDefinition $node): void { @@ -447,9 +433,7 @@ private function addHttpClientSection(ArrayNodeDefinition $node): void } /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ private function addResizerSection(ArrayNodeDefinition $node): void { @@ -482,9 +466,7 @@ private function addResizerSection(ArrayNodeDefinition $node): void } /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ private function addAdapterSection(ArrayNodeDefinition $node): void { @@ -500,9 +482,7 @@ private function addAdapterSection(ArrayNodeDefinition $node): void } /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ private function addMessengerSection(ArrayNodeDefinition $node): void { diff --git a/src/Filesystem/Replicate.php b/src/Filesystem/Replicate.php index 5f8ef3357..ca6041b5d 100644 --- a/src/Filesystem/Replicate.php +++ b/src/Filesystem/Replicate.php @@ -85,7 +85,7 @@ public function exists($key): bool * @param string $key * @param string $content * - * @return int|bool + * @return bool */ public function write($key, $content) { diff --git a/src/Form/DataTransformer/ProviderDataTransformer.php b/src/Form/DataTransformer/ProviderDataTransformer.php index 1e079b82a..0e6fb1068 100644 --- a/src/Form/DataTransformer/ProviderDataTransformer.php +++ b/src/Form/DataTransformer/ProviderDataTransformer.php @@ -48,13 +48,11 @@ public function __construct( /** * @param mixed $value * - * @return mixed - * * @phpstan-param MediaInterface|null $value * @phpstan-return MediaInterface|null */ #[\ReturnTypeWillChange] - public function transform($value) + public function transform($value): mixed { if (null === $value) { return new $this->class(); @@ -70,13 +68,11 @@ public function transform($value) /** * @param mixed $value * - * @return mixed - * * @phpstan-param MediaInterface|null $value * @phpstan-return MediaInterface|null */ #[\ReturnTypeWillChange] - public function reverseTransform($value) + public function reverseTransform($value): mixed { if (!$value instanceof MediaInterface) { return null; diff --git a/src/Form/Type/MediaType.php b/src/Form/Type/MediaType.php index 575427d0e..fcc4b1352 100644 --- a/src/Form/Type/MediaType.php +++ b/src/Form/Type/MediaType.php @@ -95,7 +95,7 @@ public function configureOptions(OptionsResolver $resolver): void ->setAllowedValues('context', array_keys($this->pool->getContexts())); } - public function getParent(): ?string + public function getParent(): string { return FormType::class; } diff --git a/src/Messenger/BackwardCompatibleMessageHandlerInterface.php b/src/Messenger/BackwardCompatibleMessageHandlerInterface.php new file mode 100644 index 000000000..f9d85f102 --- /dev/null +++ b/src/Messenger/BackwardCompatibleMessageHandlerInterface.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\MediaBundle\Messenger; + +use Symfony\Component\Messenger\Handler\MessageHandlerInterface; + +// `Symfony\Component\Messenger\Handler\MessageHandlerInterface` was removed in "symfony/messenger" 7. +// @todo: Remove this interface when dropping support for "symfony/messenger" < 7. +/** @psalm-suppress UndefinedClass */ +if (interface_exists(MessageHandlerInterface::class)) { + class_alias(MessageHandlerInterface::class, __NAMESPACE__.'\BackwardCompatibleMessageHandlerInterface'); +} else { + /** + * @internal + * + * @psalm-suppress UnrecognizedStatement + */ + interface BackwardCompatibleMessageHandlerInterface + { + } +} diff --git a/src/Messenger/GenerateThumbnailsHandler.php b/src/Messenger/GenerateThumbnailsHandler.php index 1aecab6f8..004d1a143 100644 --- a/src/Messenger/GenerateThumbnailsHandler.php +++ b/src/Messenger/GenerateThumbnailsHandler.php @@ -16,15 +16,16 @@ use Sonata\MediaBundle\Model\MediaManagerInterface; use Sonata\MediaBundle\Provider\Pool; use Sonata\MediaBundle\Thumbnail\GenerableThumbnailInterface; +use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; /** * @author Jordi Sala Morales * - * @psalm-suppress DeprecatedInterface + * NEXT_MAJOR: Stop implementing `BackwardCompatibleMessageHandlerInterface`. */ -final class GenerateThumbnailsHandler implements MessageHandlerInterface +#[AsMessageHandler] +final class GenerateThumbnailsHandler implements BackwardCompatibleMessageHandlerInterface { public function __construct( private GenerableThumbnailInterface $thumbnail, diff --git a/src/Provider/Metadata.php b/src/Provider/Metadata.php index e3052a4a0..a216d366a 100644 --- a/src/Provider/Metadata.php +++ b/src/Provider/Metadata.php @@ -40,7 +40,7 @@ public function getDescription(): ?string return $this->description; } - public function getImage(): ?string + public function getImage(): string { return $this->image; } diff --git a/src/Validator/Constraints/ValidMediaFormat.php b/src/Validator/Constraints/ValidMediaFormat.php index 971731582..22cc8dbff 100644 --- a/src/Validator/Constraints/ValidMediaFormat.php +++ b/src/Validator/Constraints/ValidMediaFormat.php @@ -27,11 +27,8 @@ public function validatedBy(): string return 'sonata.media.validator.format'; } - /** - * @return string|string[] - */ #[\ReturnTypeWillChange] - public function getTargets() + public function getTargets(): string { return self::CLASS_CONSTRAINT; } diff --git a/tests/App/config/config.yaml b/tests/App/config/config.yaml index 4f67b86e8..a57472321 100644 --- a/tests/App/config/config.yaml +++ b/tests/App/config/config.yaml @@ -5,8 +5,6 @@ framework: enabled: true translator: enabled: true - validation: - enable_annotations: false router: utf8: true http_method_override: false @@ -77,6 +75,8 @@ doctrine: dbal: driver: pdo_sqlite path: "%app.base_dir%sonata_media_test.db3" + # "dama/doctrine-test-bundle" relies on savepoints. + use_savepoints: true orm: entity_managers: default: