From 0b31497ed0e797905c621880751e37ab3d695694 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 16 May 2024 11:52:38 +0200 Subject: [PATCH] Add support for doctrine/persistence 3.0 (#257) --- .github/workflows/test-application.yaml | 8 ++++++- .../ContentMerger/ContentMerger.php | 11 ++++++++++ Content/Domain/Model/TemplateInterface.php | 4 ++-- Content/Domain/Model/TemplateTrait.php | 5 ++++- .../Sulu/Link/ContentLinkProvider.php | 4 +++- .../Sulu/Sitemap/ContentSitemapProvider.php | 2 +- .../Sulu/Teaser/ContentTeaserProvider.php | 6 +++-- .../Entity/ExampleDimensionContent.php | 5 ++++- .../Repository/ExampleRepository.php | 2 +- Tests/Application/Kernel.php | 2 +- .../Sitemap/ContentSitemapProviderTest.php | 2 +- .../SmartContent/ContentDataProviderTest.php | 2 +- .../DataMapper/WebspaceDataMapperTest.php | 2 +- .../Sulu/Page/Select/WebspaceSelectTest.php | 4 ++-- composer.json | 2 +- phpstan-baseline.neon | 22 ------------------- 16 files changed, 44 insertions(+), 39 deletions(-) delete mode 100644 phpstan-baseline.neon diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 439c9606..3cd80e9e 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -52,6 +52,12 @@ jobs: env: SYMFONY_DEPRECATIONS_HELPER: weak + - php-version: '8.3' + coverage: false + dependency-versions: 'highest' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + services: mysql: image: mysql:5.7 @@ -113,7 +119,7 @@ jobs: - name: Install and configure PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.3 extensions: ctype, iconv, mysql - name: Install composer dependencies diff --git a/Content/Application/ContentMerger/ContentMerger.php b/Content/Application/ContentMerger/ContentMerger.php index 508088ba..80a23dc8 100644 --- a/Content/Application/ContentMerger/ContentMerger.php +++ b/Content/Application/ContentMerger/ContentMerger.php @@ -17,6 +17,7 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Symfony\Component\PropertyAccess\PropertyAccessor; +use Webmozart\Assert\Assert; class ContentMerger implements ContentMergerInterface { @@ -41,6 +42,13 @@ public function __construct( $this->propertyAccessor = $propertyAccessor; } + /** + * @template T of DimensionContentInterface + * + * @param DimensionContentCollectionInterface $dimensionContentCollection + * + * @return T + */ public function merge(DimensionContentCollectionInterface $dimensionContentCollection): DimensionContentInterface { if (!$dimensionContentCollection->count()) { @@ -52,6 +60,7 @@ public function merge(DimensionContentCollectionInterface $dimensionContentColle foreach ($dimensionContentCollection as $dimensionContent) { if (!$mergedDimensionContent) { $contentRichEntity = $dimensionContent->getResource(); + /** @var T $mergedDimensionContent */ $mergedDimensionContent = $contentRichEntity->createDimensionContent(); $mergedDimensionContent->markAsMerged(); } @@ -69,6 +78,8 @@ public function merge(DimensionContentCollectionInterface $dimensionContentColle } } + Assert::notNull($mergedDimensionContent); + return $mergedDimensionContent; } } diff --git a/Content/Domain/Model/TemplateInterface.php b/Content/Domain/Model/TemplateInterface.php index 591a85b4..588c7da7 100644 --- a/Content/Domain/Model/TemplateInterface.php +++ b/Content/Domain/Model/TemplateInterface.php @@ -22,12 +22,12 @@ public function getTemplateKey(): ?string; public function setTemplateKey(string $templateKey): void; /** - * @return mixed[] + * @return array */ public function getTemplateData(): array; /** - * @param mixed[] $templateData + * @param array $templateData */ public function setTemplateData(array $templateData): void; } diff --git a/Content/Domain/Model/TemplateTrait.php b/Content/Domain/Model/TemplateTrait.php index 2bfedc14..309b1e2f 100644 --- a/Content/Domain/Model/TemplateTrait.php +++ b/Content/Domain/Model/TemplateTrait.php @@ -24,7 +24,7 @@ trait TemplateTrait private $templateKey; /** - * @var mixed[] + * @var array */ private $templateData = []; @@ -43,6 +43,9 @@ public function getTemplateData(): array return $this->templateData; } + /** + * @param array $templateData + */ public function setTemplateData(array $templateData): void { $this->templateData = $templateData; diff --git a/Content/Infrastructure/Sulu/Link/ContentLinkProvider.php b/Content/Infrastructure/Sulu/Link/ContentLinkProvider.php index 7ee470e8..42126186 100644 --- a/Content/Infrastructure/Sulu/Link/ContentLinkProvider.php +++ b/Content/Infrastructure/Sulu/Link/ContentLinkProvider.php @@ -108,7 +108,9 @@ public function preload(array $hrefs, $locale, $published = true): array */ protected function getTitle(DimensionContentInterface $dimensionContent, array $data): ?string { - return $data['title'] ?? $data['name'] ?? null; + $title = $data['title'] ?? $data['name'] ?? null; + + return \is_string($title) ? $title : null; } protected function getEntityIdField(): string diff --git a/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php b/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php index e9010ba8..234ae3eb 100644 --- a/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php +++ b/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php @@ -163,7 +163,7 @@ public function getMaxPage($scheme, $host): int { $queryBuilder = $this->createRoutesQueryBuilder(); try { - $amount = $queryBuilder + $amount = (int) $queryBuilder ->select('COUNT(' . self::ROUTE_ALIAS . ')') ->getQuery() ->getSingleScalarResult(); diff --git a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php index bb1358a6..bee1a301 100644 --- a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php +++ b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php @@ -162,7 +162,7 @@ protected function createTeaser(DimensionContentInterface $dimensionContent, arr /** * @param B $dimensionContent - * @param mixed[] $data + * @param array $data */ protected function getTitle(DimensionContentInterface $dimensionContent, array $data): ?string { @@ -172,7 +172,9 @@ protected function getTitle(DimensionContentInterface $dimensionContent, array $ } } - return $data['title'] ?? $data['name'] ?? null; + $title = $data['title'] ?? $data['name'] ?? null; + + return \is_string($title) ? $title : null; } /** diff --git a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php index b2438341..7c84ed7a 100644 --- a/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php +++ b/Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php @@ -85,10 +85,13 @@ public function getTitle(): ?string return $this->title; } + /** + * @param array $templateData + */ public function setTemplateData(array $templateData): void { if (\array_key_exists('title', $templateData)) { - $this->title = $templateData['title']; + $this->title = \is_string($templateData['title']) ? $templateData['title'] : null; } $this->parentSetTemplateData($templateData); diff --git a/Tests/Application/ExampleTestBundle/Repository/ExampleRepository.php b/Tests/Application/ExampleTestBundle/Repository/ExampleRepository.php index 1ec3f853..220c1151 100644 --- a/Tests/Application/ExampleTestBundle/Repository/ExampleRepository.php +++ b/Tests/Application/ExampleTestBundle/Repository/ExampleRepository.php @@ -185,7 +185,7 @@ public function countBy(array $filters = []): int $queryBuilder->select('COUNT(DISTINCT example.id)'); - return (int) $queryBuilder->getQuery()->getSingleScalarResult(); // @phpstan-ignore-line + return (int) $queryBuilder->getQuery()->getSingleScalarResult(); } /** diff --git a/Tests/Application/Kernel.php b/Tests/Application/Kernel.php index f58f486e..bd6d10c9 100644 --- a/Tests/Application/Kernel.php +++ b/Tests/Application/Kernel.php @@ -43,7 +43,7 @@ public function registerBundles(): iterable return $bundles; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { parent::registerContainerConfiguration($loader); $loader->load(__DIR__ . '/config/config_' . $this->getContext() . '.yml'); diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProviderTest.php index bc2b4aea..5b1a72a0 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProviderTest.php @@ -167,7 +167,7 @@ public function testGetAlias(): void /** * @param SitemapUrl[] $sitemapEntries * - * @return array + * @return array */ private function mapSitemapEntries(array $sitemapEntries): array { diff --git a/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php index d0cdf624..1077a02f 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php @@ -314,7 +314,7 @@ public function testResolveDataItems(): void /** @var int $expectedCount */ /** @var bool $expectedHasNextPage */ $dataProviderResult = $this->contentDataProvider->resolveDataItems( - $filters, + $filters, // @phpstan-ignore-line [], [ 'locale' => $locale, diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/WebspaceDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/WebspaceDataMapperTest.php index 2d33b8a2..f1ec5f11 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/WebspaceDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/WebspaceDataMapperTest.php @@ -90,7 +90,7 @@ public function testMapDefaultWebspace(): void $webspace = new Webspace(); $webspace->setKey('default-webspace'); - $this->webspaceCollection->setWebspaces([$webspace]); + $this->webspaceCollection->setWebspaces(['default-webspace' => $webspace]); $authorMapper = $this->createWebspaceDataMapperInstance(); $authorMapper->map($unlocalizedDimensionContent, $localizedDimensionContent, $data); diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Page/Select/WebspaceSelectTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Page/Select/WebspaceSelectTest.php index 29a4b6af..6bff0831 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Page/Select/WebspaceSelectTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Page/Select/WebspaceSelectTest.php @@ -49,8 +49,8 @@ public function testGetValues(): void $webspaceB->setKey('webspace-b'); $webspaceB->setName('Webspace B'); $webspaceCollection = new WebspaceCollection([ - $webspaceA, - $webspaceB, + 'webspace-a' => $webspaceA, + 'webspace-b' => $webspaceB, ]); $this->webspaceManager->getWebspaceCollection() diff --git a/composer.json b/composer.json index afed83e3..e1ee0eb5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "doctrine/inflector": "^1.4.1 || ^2.0.1", "doctrine/collections": "^1.0", "doctrine/orm": "^2.5.3", - "doctrine/persistence": "^1.3 || ^2.0", + "doctrine/persistence": "^1.3 || ^2.0 || ^3.0", "doctrine/doctrine-bundle": "^1.10 || ^2.0", "friendsofsymfony/rest-bundle": "^2.6 || ^3.0", "massive/search-bundle": "^2.4", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index ea83dcf9..00000000 --- a/phpstan-baseline.neon +++ /dev/null @@ -1,22 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\\\|null given\\.$#" - count: 1 - path: Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php - - - - message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\\\|null given\\.$#" - count: 2 - path: Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php - - - - message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\\\|null given\\.$#" - count: 1 - path: Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php - - - - message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\\\|null given\\.$#" - count: 3 - path: Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php -