From 7568fc2076a1de810b1839a6e9062165c86aedba Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Fri, 29 Mar 2024 14:44:01 +0100 Subject: [PATCH] Run lint task under PHP 8.3 (#670) --- .circleci/config.yml | 1 + .github/workflows/test-application.yaml | 17 ++++++++++++++++- Command/ArticleImportCommand.php | 2 +- Content/ArticleDataProvider.php | 4 ++-- Controller/ArticleController.php | 4 ++-- DependencyInjection/SuluArticleExtension.php | 1 + Document/ArticlePageDocument.php | 2 -- Document/ArticleViewDocument.php | 4 ++-- Document/ArticleViewDocumentInterface.php | 8 ++------ Document/LocalizationStateViewObject.php | 2 +- .../ArticleViewDocumentRepository.php | 4 ++-- .../WebsiteArticleUrlsSubscriber.php | 6 +++--- Document/Structure/ArticleBridge.php | 2 +- Document/Subscriber/ArticleSubscriber.php | 2 +- Export/ExportFormatNotFoundException.php | 2 +- Import/ArticleImport.php | 4 ++-- Import/ArticleImportInterface.php | 2 +- ListBuilder/ElasticSearchFieldDescriptor.php | 6 +++--- .../ElasticSearchFieldDescriptorBuilder.php | 4 ++-- Routing/ArticleRouteDefaultProvider.php | 4 ++-- Tests/Application/bin/console.php | 2 +- .../Controller/ArticlePageControllerTest.php | 3 --- .../ArticleSelectionContentTypeTest.php | 18 +++++++++--------- .../Subscriber/ArticleSubscriberTest.php | 2 +- Twig/ArticleViewDocumentTwigExtension.php | 8 ++++---- composer.json | 2 +- phpstan-baseline.neon | 5 ----- 27 files changed, 62 insertions(+), 59 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5b3b978dc..3e2aa8927 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,6 +27,7 @@ jobs: sudo docker-php-ext-install pdo_mysql gd parallel: true - run: echo -e "memory_limit=2G" | sudo tee /usr/local/etc/php/php.ini > /dev/null + - run: /usr/local/bin/composer remove php-cs-fixer/shim --dev --no-update - run: /usr/local/bin/composer require "elasticsearch/elasticsearch:~7.5.2" --no-update - restore_cache: keys: diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 32033a84f..6c16f9b08 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -82,6 +82,18 @@ jobs: SYMFONY_DEPRECATIONS_HELPER: weak ELASTICSEARCH_HOST: '127.0.0.1:9200' + - php-version: '8.3' + elasticsearch-version: '7.11.1' + elasticsearch-package-constraint: '~7.11.0' + phpcr-transport: jackrabbit + dependency-versions: 'highest' + php-extensions: 'ctype, iconv, mysql, imagick' + tools: 'composer:v2' + phpstan: false + env: + SYMFONY_DEPRECATIONS_HELPER: weak + ELASTICSEARCH_HOST: '127.0.0.1:9200' + services: mysql: image: mysql:5.7 @@ -124,6 +136,9 @@ jobs: tools: ${{ matrix.tools }} coverage: none + - name: Remove not required tooling + run: composer remove php-cs-fixer/shim --dev --no-interaction --no-update + - name: Require elasticsearch dependency run: composer require --dev elasticsearch/elasticsearch:"${{ matrix.elasticsearch-package-constraint }}" --no-interaction --no-update @@ -155,7 +170,7 @@ jobs: - name: Install and configure PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 extensions: 'ctype, iconv, mysql, imagick' tools: 'composer:v2' coverage: none diff --git a/Command/ArticleImportCommand.php b/Command/ArticleImportCommand.php index e2051d7ac..6275a6756 100644 --- a/Command/ArticleImportCommand.php +++ b/Command/ArticleImportCommand.php @@ -37,7 +37,7 @@ class ArticleImportCommand extends Command */ private $logger; - public function __construct(ArticleImportInterface $articleImporter, LoggerInterface $logger = null) + public function __construct(ArticleImportInterface $articleImporter, ?LoggerInterface $logger = null) { parent::__construct(); diff --git a/Content/ArticleDataProvider.php b/Content/ArticleDataProvider.php index 75b2bda51..b52dd0602 100644 --- a/Content/ArticleDataProvider.php +++ b/Content/ArticleDataProvider.php @@ -98,8 +98,8 @@ public function __construct( ArticleResourceItemFactory $articleResourceItemFactory, string $articleDocumentClass, int $defaultLimit, - MetadataProviderInterface $formMetadataProvider = null, - TokenStorageInterface $tokenStorage = null, + ?MetadataProviderInterface $formMetadataProvider = null, + ?TokenStorageInterface $tokenStorage = null, bool $hasAudienceTargeting = false ) { $this->searchManager = $searchManager; diff --git a/Controller/ArticleController.php b/Controller/ArticleController.php index eda130365..0b011eaea 100644 --- a/Controller/ArticleController.php +++ b/Controller/ArticleController.php @@ -333,8 +333,8 @@ public function cgetAction(Request $request): Response $search->addQuery(new MatchAllQuery()); } - if (null !== $this->restHelper->getSortColumn() && - $sortField = $this->getSortFieldName($this->restHelper->getSortColumn()) + if (null !== $this->restHelper->getSortColumn() + && $sortField = $this->getSortFieldName($this->restHelper->getSortColumn()) ) { $search->addSort( new FieldSort($sortField, $this->restHelper->getSortOrder()) diff --git a/DependencyInjection/SuluArticleExtension.php b/DependencyInjection/SuluArticleExtension.php index 0afe42799..7b6cbc07f 100644 --- a/DependencyInjection/SuluArticleExtension.php +++ b/DependencyInjection/SuluArticleExtension.php @@ -295,6 +295,7 @@ public function load(array $configs, ContainerBuilder $container) $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); + /** @var array $bundles */ $bundles = $container->getParameter('kernel.bundles'); if (\array_key_exists('SuluAutomationBundle', $bundles)) { $loader->load('automation.xml'); diff --git a/Document/ArticlePageDocument.php b/Document/ArticlePageDocument.php index d99d80753..d923aaa11 100644 --- a/Document/ArticlePageDocument.php +++ b/Document/ArticlePageDocument.php @@ -145,8 +145,6 @@ public function setTitle($title) /** * Returns pageTitle. - * - * @return string */ public function getPageTitle(): ?string { diff --git a/Document/ArticleViewDocument.php b/Document/ArticleViewDocument.php index dd77e24fd..deb85c183 100644 --- a/Document/ArticleViewDocument.php +++ b/Document/ArticleViewDocument.php @@ -489,7 +489,7 @@ public function getAuthored() return $this->authored; } - public function setAuthored(\DateTime $authored = null) + public function setAuthored(?\DateTime $authored = null) { $this->authored = $authored; @@ -537,7 +537,7 @@ public function getPublished() return $this->published; } - public function setPublished(\DateTime $published = null) + public function setPublished(?\DateTime $published = null) { $this->published = $published; diff --git a/Document/ArticleViewDocumentInterface.php b/Document/ArticleViewDocumentInterface.php index ba73cfcbe..ef28f1053 100644 --- a/Document/ArticleViewDocumentInterface.php +++ b/Document/ArticleViewDocumentInterface.php @@ -267,11 +267,9 @@ public function getAuthored(); /** * Set authored date. * - * @param \DateTime $authored - * * @return $this */ - public function setAuthored(\DateTime $authored = null); + public function setAuthored(?\DateTime $authored = null); /** * Returns author full name. @@ -331,11 +329,9 @@ public function getPublished(); /** * Set published. * - * @param \DateTime $published - * * @return $this */ - public function setPublished(\DateTime $published = null); + public function setPublished(?\DateTime $published = null); /** * Get published state. diff --git a/Document/LocalizationStateViewObject.php b/Document/LocalizationStateViewObject.php index 49250a702..d31804e01 100644 --- a/Document/LocalizationStateViewObject.php +++ b/Document/LocalizationStateViewObject.php @@ -35,7 +35,7 @@ class LocalizationStateViewObject */ public $locale; - public function __construct(string $state = null, string $locale = null) + public function __construct(?string $state = null, ?string $locale = null) { $this->state = $state; $this->locale = $locale; diff --git a/Document/Repository/ArticleViewDocumentRepository.php b/Document/Repository/ArticleViewDocumentRepository.php index 1a8d706e8..1cb3926b8 100644 --- a/Document/Repository/ArticleViewDocumentRepository.php +++ b/Document/Repository/ArticleViewDocumentRepository.php @@ -76,7 +76,7 @@ public function __construct( public function findRecent( ?string $excludeUuid = null, int $limit = self::DEFAULT_LIMIT, - array $types = null, + ?array $types = null, ?string $locale = null, ?string $webspaceKey = null ): DocumentIterator { @@ -97,7 +97,7 @@ public function findRecent( public function findSimilar( string $uuid, int $limit = self::DEFAULT_LIMIT, - array $types = null, + ?array $types = null, ?string $locale = null, ?string $webspaceKey = null ): DocumentIterator { diff --git a/Document/Serializer/WebsiteArticleUrlsSubscriber.php b/Document/Serializer/WebsiteArticleUrlsSubscriber.php index 9d16099ea..2bd0d3a80 100644 --- a/Document/Serializer/WebsiteArticleUrlsSubscriber.php +++ b/Document/Serializer/WebsiteArticleUrlsSubscriber.php @@ -67,9 +67,9 @@ public function __construct( RequestStack $requestStack, RouteRepositoryInterface $routeRepository, WebspaceManagerInterface $webspaceManager, - DocumentInspector $documentInspector = null, - DocumentRegistry $documentRegistry = null, - NodeManager $nodeManager = null + ?DocumentInspector $documentInspector = null, + ?DocumentRegistry $documentRegistry = null, + ?NodeManager $nodeManager = null ) { $this->requestStack = $requestStack; $this->routeRepository = $routeRepository; diff --git a/Document/Structure/ArticleBridge.php b/Document/Structure/ArticleBridge.php index 0d3407f3f..4819afc26 100644 --- a/Document/Structure/ArticleBridge.php +++ b/Document/Structure/ArticleBridge.php @@ -21,7 +21,7 @@ class ArticleBridge extends StructureBridge implements RoutableStructureInterfac /** * @var string */ - private $webspaceKey = null; + private $webspaceKey; /** * @var string diff --git a/Document/Subscriber/ArticleSubscriber.php b/Document/Subscriber/ArticleSubscriber.php index 9aee06958..1d0f114a6 100644 --- a/Document/Subscriber/ArticleSubscriber.php +++ b/Document/Subscriber/ArticleSubscriber.php @@ -127,7 +127,7 @@ public static function getSubscribedEvents() Events::FLUSH => [['handleFlush', -2048], ['handleFlushLive', -2048]], Events::COPY => ['handleCopy'], Events::METADATA_LOAD => ['handleMetadataLoad'], - EVENTS::REMOVE_LOCALE => [['handleRemoveLocale', -500], ['handleRemoveLocaleLive', -500]], + Events::REMOVE_LOCALE => [['handleRemoveLocale', -500], ['handleRemoveLocaleLive', -500]], ]; } diff --git a/Export/ExportFormatNotFoundException.php b/Export/ExportFormatNotFoundException.php index 29829d65d..ce20d7add 100644 --- a/Export/ExportFormatNotFoundException.php +++ b/Export/ExportFormatNotFoundException.php @@ -18,7 +18,7 @@ class ExportFormatNotFoundException extends \Exception */ private $format; - public function __construct(string $format, int $code = 0, \Throwable $previous = null) + public function __construct(string $format, int $code = 0, ?\Throwable $previous = null) { parent::__construct(\sprintf('No format "%s" configured for Snippet export', $format), $code, $previous); diff --git a/Import/ArticleImport.php b/Import/ArticleImport.php index ddb8c5e4e..f3ddee701 100644 --- a/Import/ArticleImport.php +++ b/Import/ArticleImport.php @@ -93,7 +93,7 @@ public function __construct( ExtensionManagerInterface $extensionManager, ImportManagerInterface $importManager, FormatImportInterface $xliff12, - LoggerInterface $logger = null + ?LoggerInterface $logger = null ) { parent::__construct($importManager, $legacyPropertyFactory, ['1.2.xliff' => $xliff12]); @@ -108,7 +108,7 @@ public function __construct( public function import( string $locale, string $filePath, - OutputInterface $output = null, + ?OutputInterface $output = null, string $format = '1.2.xliff', bool $overrideSettings = false ): ImportResult { diff --git a/Import/ArticleImportInterface.php b/Import/ArticleImportInterface.php index ec79b6711..322e15e12 100644 --- a/Import/ArticleImportInterface.php +++ b/Import/ArticleImportInterface.php @@ -18,7 +18,7 @@ interface ArticleImportInterface public function import( string $locale, string $filePath, - OutputInterface $output = null, + ?OutputInterface $output = null, string $format = '1.2.xliff', bool $overrideSettings = false ): ImportResult; diff --git a/ListBuilder/ElasticSearchFieldDescriptor.php b/ListBuilder/ElasticSearchFieldDescriptor.php index 33b5b4be6..b2fdb489d 100644 --- a/ListBuilder/ElasticSearchFieldDescriptor.php +++ b/ListBuilder/ElasticSearchFieldDescriptor.php @@ -20,7 +20,7 @@ */ class ElasticSearchFieldDescriptor extends FieldDescriptor { - public static function create(string $name, string $translation = null): ElasticSearchFieldDescriptorBuilder + public static function create(string $name, ?string $translation = null): ElasticSearchFieldDescriptorBuilder { return new ElasticSearchFieldDescriptorBuilder($name, $translation); } @@ -37,8 +37,8 @@ public static function create(string $name, string $translation = null): Elastic public function __construct( string $name, - string $sortField = null, - string $translation = null, + ?string $sortField = null, + ?string $translation = null, string $visibility = FieldDescriptorInterface::VISIBILITY_YES, string $searchability = FieldDescriptorInterface::SEARCHABILITY_NEVER, string $type = '', diff --git a/ListBuilder/ElasticSearchFieldDescriptorBuilder.php b/ListBuilder/ElasticSearchFieldDescriptorBuilder.php index 33b4dbfc8..03b6ddd21 100644 --- a/ListBuilder/ElasticSearchFieldDescriptorBuilder.php +++ b/ListBuilder/ElasticSearchFieldDescriptorBuilder.php @@ -28,7 +28,7 @@ final class ElasticSearchFieldDescriptorBuilder /** * @var string */ - private $sortField = null; + private $sortField; /** * @var string @@ -55,7 +55,7 @@ final class ElasticSearchFieldDescriptorBuilder */ private $searchField = ''; - public function __construct(string $name, string $translation = null) + public function __construct(string $name, ?string $translation = null) { $this->name = $name; $this->translation = $translation; diff --git a/Routing/ArticleRouteDefaultProvider.php b/Routing/ArticleRouteDefaultProvider.php index 71f9bc6b6..71237175e 100644 --- a/Routing/ArticleRouteDefaultProvider.php +++ b/Routing/ArticleRouteDefaultProvider.php @@ -151,8 +151,8 @@ public function isPublished($entityClass, $id, $locale) } $webspace = $this->requestAnalyzer->getWebspace(); - if (!$webspace || - ( + if (!$webspace + || ( $this->webspaceResolver->resolveMainWebspace($object) !== $webspace->getKey() && !\in_array($webspace->getKey(), $this->webspaceResolver->resolveAdditionalWebspaces($object)) ) diff --git a/Tests/Application/bin/console.php b/Tests/Application/bin/console.php index 0c8d139c1..44e05b930 100755 --- a/Tests/Application/bin/console.php +++ b/Tests/Application/bin/console.php @@ -33,7 +33,7 @@ if (\class_exists(Debug::class)) { Debug::enable(); } else { - \Symfony\Component\Debug\Debug::enable(); + Symfony\Component\Debug\Debug::enable(); } } diff --git a/Tests/Functional/Controller/ArticlePageControllerTest.php b/Tests/Functional/Controller/ArticlePageControllerTest.php index faf478457..9c70f9f5c 100644 --- a/Tests/Functional/Controller/ArticlePageControllerTest.php +++ b/Tests/Functional/Controller/ArticlePageControllerTest.php @@ -370,9 +370,6 @@ private function purgeIndex() } /** - * @param $uuid - * @param $locale - * * @return ArticleViewDocumentInterface */ private function findViewDocument($uuid, $locale) diff --git a/Tests/Unit/Content/ArticleSelectionContentTypeTest.php b/Tests/Unit/Content/ArticleSelectionContentTypeTest.php index 11f0d2d22..309eeee79 100644 --- a/Tests/Unit/Content/ArticleSelectionContentTypeTest.php +++ b/Tests/Unit/Content/ArticleSelectionContentTypeTest.php @@ -55,15 +55,15 @@ function($id) { Argument::that( function(IdsQuery $query) use ($ids) { return $query->toArray() === [ - 'ids' => [ - 'values' => \array_map( - function($id) { - return $id . '-de'; - }, - $ids - ), - ], - ]; + 'ids' => [ + 'values' => \array_map( + function($id) { + return $id . '-de'; + }, + $ids + ), + ], + ]; } ) )->shouldBeCalled(); diff --git a/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php b/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php index a35a8b86e..5c96e1726 100644 --- a/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php +++ b/Tests/Unit/Document/Subscriber/ArticleSubscriberTest.php @@ -508,7 +508,7 @@ public function testHydratePageDataShadow() $this->document->reveal() )->willReturn(LocalizationState::SHADOW); - $propertyNameEN = 'i18n:' . 'en' . '-' . ArticleSubscriber::PAGES_PROPERTY; + $propertyNameEN = 'i18n:en-' . ArticleSubscriber::PAGES_PROPERTY; $this->propertyEncoder->localizedSystemName(ArticleSubscriber::PAGES_PROPERTY, 'en') ->willReturn($propertyNameEN); diff --git a/Twig/ArticleViewDocumentTwigExtension.php b/Twig/ArticleViewDocumentTwigExtension.php index a89b22e0a..761cc0282 100644 --- a/Twig/ArticleViewDocumentTwigExtension.php +++ b/Twig/ArticleViewDocumentTwigExtension.php @@ -93,7 +93,7 @@ public function getFunctions() */ public function loadRecent( int $limit = ArticleViewDocumentRepository::DEFAULT_LIMIT, - array $types = null, + ?array $types = null, ?string $locale = null, bool $ignoreWebspaces = false ): array { @@ -131,13 +131,13 @@ public function loadRecent( /** * Loads similar articles with given parameters. * - * @throws ArticleInRequestNotFoundException - * * @return ArticleResourceItem[] + * + * @throws ArticleInRequestNotFoundException */ public function loadSimilar( int $limit = ArticleViewDocumentRepository::DEFAULT_LIMIT, - array $types = null, + ?array $types = null, ?string $locale = null, bool $ignoreWebspaces = false ): array { diff --git a/composer.json b/composer.json index ce3d6fff7..a53486854 100644 --- a/composer.json +++ b/composer.json @@ -35,12 +35,12 @@ }, "require-dev": { "doctrine/data-fixtures": "^1.1", - "friendsofphp/php-cs-fixer": "^3.0", "handcraftedinthealps/zendsearch": "^2.0", "jackalope/jackalope-doctrine-dbal": "^1.3.4", "jackalope/jackalope-jackrabbit": "^1.3", "jangregor/phpstan-prophecy": "^1.0", "massive/build-bundle": "^0.3 || ^0.4 || ^0.5", + "php-cs-fixer/shim": "^3.0", "phpcr/phpcr-shell": "^1.1", "phpspec/prophecy": "^1.15", "phpstan/phpstan": "^1.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 36c273270..76eaf1d6a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -505,11 +505,6 @@ parameters: count: 1 path: DependencyInjection/StructureValidatorCompilerPass.php - - - message: "#^Call to function array_key_exists\\(\\) with 'SuluAutomationBundle' and array\\{FrameworkBundle\\: string, TwigBundle\\: string, SuluCoreBundle\\: string, DoctrineBundle\\: string, DoctrinePHPCRBundle\\: string, PhpcrMigrationsBundle\\: string, StofDoctrineExtensionsBundle\\: string, JMSSerializerBundle\\: string, \\.\\.\\.\\} will always evaluate to false\\.$#" - count: 1 - path: DependencyInjection/SuluArticleExtension.php - - message: "#^Method Sulu\\\\Bundle\\\\ArticleBundle\\\\DependencyInjection\\\\SuluArticleExtension\\:\\:appendDefaultAuthor\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" count: 1