From 312a642269ec111889312d476bca0f641de83e54 Mon Sep 17 00:00:00 2001 From: Luca Rath-Heel Date: Tue, 18 Oct 2022 15:24:38 +0200 Subject: [PATCH 1/3] Use RoutableStructureInterface --- .../Sulu/Structure/ContentStructureBridge.php | 7 ++- .../Structure/RoutableStructureInterface.php | 61 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php diff --git a/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php b/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php index 4470f124..152fb60f 100644 --- a/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php +++ b/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php @@ -26,7 +26,7 @@ use Sulu\Component\Content\Metadata\PropertyMetadata; use Sulu\Component\Content\Metadata\StructureMetadata; -class ContentStructureBridge implements StructureInterface +class ContentStructureBridge implements StructureInterface, RoutableStructureInterface { /** * @var StructureMetadata @@ -130,6 +130,11 @@ public function getController(): ?string return $this->structure->getController(); } + public function getCacheLifeTime() + { + return $this->structure->getCacheLifetime(); + } + public function getCreator(): ?int { return null; diff --git a/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php b/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php new file mode 100644 index 00000000..38d442b8 --- /dev/null +++ b/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php @@ -0,0 +1,61 @@ + Date: Tue, 18 Oct 2022 15:38:18 +0200 Subject: [PATCH 2/3] Add missing test --- .../Sulu/Structure/RoutableStructureInterface.php | 6 ++---- .../Sulu/Structure/ContentStructureBridgeTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php b/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php index 38d442b8..408fca14 100644 --- a/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php +++ b/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php @@ -13,16 +13,14 @@ namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure; -use Sulu\Component\Content\Compat\RoutableStructureInterface as SuluRoutableStructureInterface; - -if (\interface_exists(SuluRoutableStructureInterface::class)) { +if (interface_exists(\Sulu\Component\Content\Compat\RoutableStructureInterface::class)) { /** * @deprecated will be removed, as soon as the ArticleBundle rises the minimum requirement of sulu to a version, * where this interface exists * * @internal */ - interface RoutableStructureInterface extends SuluRoutableStructureInterface + interface RoutableStructureInterface extends \Sulu\Component\Content\Compat\RoutableStructureInterface { } } else { diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeTest.php index e257b1ed..58e60c9f 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeTest.php @@ -157,6 +157,20 @@ public function testGetController(): void ); } + public function testGetCacheLifeTime(): void + { + $structure = $this->prophesize(StructureMetadata::class); + + $structure->getCacheLifeTime()->willReturn(['type' => 'type', 'value' => 'value']); + + $structure = $this->createStructureBridge(null, $structure->reveal()); + + $this->assertSame( + ['type' => 'type', 'value' => 'value'], + $structure->getCacheLifeTime() + ); + } + public function testGetKey(): void { $structure = $this->prophesize(StructureMetadata::class); From 5902d262a5f0563885f05beac25daace2ea79e2f Mon Sep 17 00:00:00 2001 From: Luca Rath-Heel Date: Tue, 18 Oct 2022 17:40:18 +0200 Subject: [PATCH 3/3] Update phpstan --- .../DataMapper/RoutableDataMapper.php | 7 +- .../DataMapper/SeoDataMapper.php | 19 ++- .../DataMapper/WorkflowDataMapper.php | 1 + .../ContentIndexer/ContentIndexer.php | 1 + .../ContentMerger/Merger/ExcerptMerger.php | 4 +- .../Normalizer/TemplateNormalizer.php | 4 +- .../ContentResolver/ContentResolver.php | 3 + .../ContentWorkflow/ContentWorkflow.php | 3 + .../DimensionContentCollectionFactory.php | 4 +- .../Exception/ContentNotFoundException.php | 5 +- .../DimensionContentQueryEnhancer.php | 11 -- .../Doctrine/MetadataLoader.php | 2 + .../Infrastructure/Doctrine/RouteRemover.php | 5 +- .../Sulu/Admin/ContentViewBuilderFactory.php | 5 +- .../Sulu/Preview/ContentObjectProvider.php | 4 + .../Sulu/Search/ContentReindexProvider.php | 2 + .../Sulu/Sitemap/ContentSitemapProvider.php | 10 +- .../ContentDataProviderRepository.php | 33 ++-- .../Sulu/Structure/ContentDocument.php | 2 +- .../Sulu/Structure/ContentStructureBridge.php | 14 +- .../ContentStructureBridgeFactory.php | 2 +- .../Structure/RoutableStructureInterface.php | 6 +- .../Sulu/Teaser/ContentTeaserProvider.php | 14 +- .../Compiler/SettingsFormPass.php | 2 +- DependencyInjection/SuluContentExtension.php | 2 +- Resources/config/services.xml | 5 +- .../ExampleTestExtension.php | 2 +- .../ExampleTestBundle/Entity/Example.php | 4 +- .../Repository/ExampleRepository.php | 20 ++- .../Teaser/ExampleTeaserProvider.php | 4 +- .../DimensionContentRepositoryTest.php | 20 ++- .../Search/ContentReindexProviderTest.php | 24 ++- .../ContentSearchMetadataProviderTest.php | 8 +- .../SmartContent/ContentDataProviderTest.php | 148 +++++++++--------- .../Sulu/Teaser/ContentTeaserProviderTest.php | 21 +-- .../Integration/ExampleControllerTest.php | 8 +- Tests/Traits/CreateCategoryTrait.php | 7 +- Tests/Traits/CreateExampleTrait.php | 11 +- .../Doctrine/RouteRemoverTest.php | 4 +- .../Admin/ContentViewBuilderFactoryTest.php | 2 +- .../Preview/ContentObjectProviderTest.php | 24 +-- .../DimensionContentMockWrapperTrait.php | 65 ++++++-- Tests/Unit/Mocks/RoutableMockWrapperTrait.php | 14 +- Tests/Unit/Mocks/TemplateMockWrapperTrait.php | 24 ++- Tests/Unit/Mocks/WorkflowMockWrapperTrait.php | 24 ++- composer.json | 14 +- phpstan-baseline.neon | 20 --- phpstan.neon | 6 +- 48 files changed, 394 insertions(+), 250 deletions(-) diff --git a/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php index fc656d20..82001e19 100644 --- a/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/RoutableDataMapper.php @@ -130,10 +130,11 @@ public function map( throw new \RuntimeException(\sprintf('No route mapping found for "%s".', $resourceKey)); } + /** @var string|null $routePath */ $routePath = $data[$name] ?? null; if (!$routePath) { - /** @var mixed $routeGenerationData */ + /** @var mixed[] $routeGenerationData */ $routeGenerationData = \array_merge( $data, [ @@ -161,7 +162,7 @@ public function map( // route should only be updated in live dimension $route = $this->routeManager->createOrUpdateByAttributes( $entityClass, - (string) $localizedDimensionContent->getResourceId(), + (string) $localizedDimensionContent->getResourceId(), // @phpstan-ignore-line $locale, $routePath, false @@ -173,7 +174,7 @@ public function map( $route->setPath($routePath); $route->setLocale($locale); $route->setEntityClass($entityClass); - $route->setEntityId((string) $localizedDimensionContent->getResourceId()); + $route->setEntityId((string) $localizedDimensionContent->getResourceId()); // @phpstan-ignore-line $routePath = $this->conflictResolver->resolve($route) ->getPath(); diff --git a/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php index e0ccec17..ed604359 100644 --- a/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/SeoDataMapper.php @@ -27,11 +27,28 @@ public function map( return; } + /** @var array{ + * seoTitle?: string|null, + * seoDescription?: string|null, + * seoKeywords?: string|null, + * seoCanonicalUrl?: string|null, + * seoHideInSitemap?: bool, + * seoNoFollow?: bool, + * seoNoIndex?: bool, + * } $data */ $this->setSeoData($localizedDimensionContent, $data); } /** - * @param mixed[] $data + * @param array{ + * seoTitle?: string|null, + * seoDescription?: string|null, + * seoKeywords?: string|null, + * seoCanonicalUrl?: string|null, + * seoHideInSitemap?: bool, + * seoNoFollow?: bool, + * seoNoIndex?: bool, + * } $data */ private function setSeoData(SeoInterface $dimensionContent, array $data): void { diff --git a/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php index 61f83182..84637456 100644 --- a/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/WorkflowDataMapper.php @@ -73,6 +73,7 @@ private function setPublishedToLiveDimension(WorkflowInterface $object, array $d return; } + /** @var string|null $published */ $published = $data['published'] ?? null; if (!$published) { diff --git a/Content/Application/ContentIndexer/ContentIndexer.php b/Content/Application/ContentIndexer/ContentIndexer.php index e22c73cf..d0e02f5b 100644 --- a/Content/Application/ContentIndexer/ContentIndexer.php +++ b/Content/Application/ContentIndexer/ContentIndexer.php @@ -65,6 +65,7 @@ public function deindex(string $resourceKey, $id, array $dimensionAttributes = [ $locale = $dimensionAttributes['locale'] ?? null; $stage = $dimensionAttributes['stage'] ?? null; + /** @var scalar $id */ $search = $this->searchManager->createSearch(\sprintf('__id:"%s"', $id)) ->indexes($this->getIndexes($resourceKey, $stage)); diff --git a/Content/Application/ContentMerger/Merger/ExcerptMerger.php b/Content/Application/ContentMerger/Merger/ExcerptMerger.php index 676b7dfc..3f041cd5 100644 --- a/Content/Application/ContentMerger/Merger/ExcerptMerger.php +++ b/Content/Application/ContentMerger/Merger/ExcerptMerger.php @@ -52,13 +52,13 @@ public function merge(object $targetObject, object $sourceObject): void } if ($excerptTags = $sourceObject->getExcerptTags()) { - if (!empty($excerptTags)) { + if ([] !== $excerptTags) { $targetObject->setExcerptTags($excerptTags); } } if ($excerptCategories = $sourceObject->getExcerptCategories()) { - if (!empty($excerptCategories)) { + if ([] !== $excerptCategories) { $targetObject->setExcerptCategories($excerptCategories); } } diff --git a/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizer.php b/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizer.php index 6497099f..80a25ee8 100644 --- a/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizer.php +++ b/Content/Application/ContentNormalizer/Normalizer/TemplateNormalizer.php @@ -23,7 +23,9 @@ public function enhance(object $object, array $normalizedData): array return $normalizedData; } - $normalizedData = \array_merge($normalizedData['templateData'], $normalizedData); + /** @var mixed[] $templateData */ + $templateData = $normalizedData['templateData']; + $normalizedData = \array_merge($templateData, $normalizedData); unset($normalizedData['templateData']); $normalizedData['template'] = $normalizedData['templateKey']; diff --git a/Content/Application/ContentResolver/ContentResolver.php b/Content/Application/ContentResolver/ContentResolver.php index 36f4f1f9..ea786e6c 100644 --- a/Content/Application/ContentResolver/ContentResolver.php +++ b/Content/Application/ContentResolver/ContentResolver.php @@ -39,6 +39,9 @@ public function __construct( $this->contentMerger = $contentMerger; } + /** + * @param array $dimensionAttributes + */ public function resolve(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes): DimensionContentInterface { $dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionAttributes); diff --git a/Content/Application/ContentWorkflow/ContentWorkflow.php b/Content/Application/ContentWorkflow/ContentWorkflow.php index 5b18ab23..d8e85d31 100644 --- a/Content/Application/ContentWorkflow/ContentWorkflow.php +++ b/Content/Application/ContentWorkflow/ContentWorkflow.php @@ -86,7 +86,10 @@ public function apply( */ $dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionAttributes); + + /** @var array $dimensionAttributes */ $dimensionAttributes = $dimensionContentCollection->getDimensionAttributes(); + $localizedDimensionContent = $dimensionContentCollection->getDimensionContent($dimensionAttributes); if (!$localizedDimensionContent) { diff --git a/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactory.php b/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactory.php index 246fb743..eeaf2894 100644 --- a/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactory.php +++ b/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactory.php @@ -70,8 +70,10 @@ public function create( ); } - $localizedDimensionContent = null; + /** @var string|null $locale */ $locale = $dimensionAttributes['locale'] ?? null; + $localizedDimensionContent = null; + if ($locale) { $localizedDimensionContent = $dimensionContentCollection->getDimensionContent($dimensionAttributes); diff --git a/Content/Domain/Exception/ContentNotFoundException.php b/Content/Domain/Exception/ContentNotFoundException.php index b5bba848..bab38453 100644 --- a/Content/Domain/Exception/ContentNotFoundException.php +++ b/Content/Domain/Exception/ContentNotFoundException.php @@ -22,9 +22,12 @@ class ContentNotFoundException extends \Exception */ public function __construct(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes) { + /** @var string|int $id */ + $id = $contentRichEntity->getId(); + parent::__construct(\sprintf( 'Could not load content with id "%s" and attributes: %s', - $contentRichEntity->getId(), + $id, \json_encode($dimensionAttributes) )); } diff --git a/Content/Infrastructure/Doctrine/DimensionContentQueryEnhancer.php b/Content/Infrastructure/Doctrine/DimensionContentQueryEnhancer.php index 69eedc22..7535e7f4 100644 --- a/Content/Infrastructure/Doctrine/DimensionContentQueryEnhancer.php +++ b/Content/Infrastructure/Doctrine/DimensionContentQueryEnhancer.php @@ -29,17 +29,6 @@ */ class DimensionContentQueryEnhancer { - /** - * @var ContentMetadataInspectorInterface - */ - private $contentMetadataInspector; - - public function __construct( - ContentMetadataInspectorInterface $contentMetadataInspector - ) { - $this->contentMetadataInspector = $contentMetadataInspector; - } - /** * Withs represents additional selects which can be load to join and select specific sub entities. * They are used by groups and fields. diff --git a/Content/Infrastructure/Doctrine/MetadataLoader.php b/Content/Infrastructure/Doctrine/MetadataLoader.php index 9990c1d1..87ed16f1 100644 --- a/Content/Infrastructure/Doctrine/MetadataLoader.php +++ b/Content/Infrastructure/Doctrine/MetadataLoader.php @@ -116,6 +116,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void * @codeCoverageIgnore * * @param ClassMetadataInfo $metadata + * @param class-string $class */ private function addManyToOne( LoadClassMetadataEventArgs $event, @@ -148,6 +149,7 @@ private function addManyToOne( /** * @param ClassMetadataInfo $metadata + * @param class-string $class */ private function addManyToMany( LoadClassMetadataEventArgs $event, diff --git a/Content/Infrastructure/Doctrine/RouteRemover.php b/Content/Infrastructure/Doctrine/RouteRemover.php index 0bbe3ede..fb30d9e1 100644 --- a/Content/Infrastructure/Doctrine/RouteRemover.php +++ b/Content/Infrastructure/Doctrine/RouteRemover.php @@ -82,7 +82,10 @@ public function preRemove(LifecycleEventArgs $event): void return; } - foreach ($this->routeRepository->findAllByEntity($entityClass, $object->getId()) as $route) { + /** @var string $entityId */ + $entityId = $object->getId(); + + foreach ($this->routeRepository->findAllByEntity($entityClass, $entityId) as $route) { $event->getEntityManager()->remove($route); } } diff --git a/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactory.php b/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactory.php index e0be2095..21e17568 100644 --- a/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactory.php +++ b/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactory.php @@ -298,7 +298,10 @@ private function createSettingsFormView( ): ViewBuilderInterface { $forms = []; foreach ($this->settingsForms as $key => $tag) { - if (\is_subclass_of($dimensionContentClass, $tag['instanceOf'])) { + /** @var string $instanceOf */ + $instanceOf = $tag['instanceOf']; + + if (\is_subclass_of($dimensionContentClass, $instanceOf)) { $forms[] = $key; } } diff --git a/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php b/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php index 2c0a2e87..1bf46624 100644 --- a/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php +++ b/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php @@ -98,6 +98,7 @@ public function getObject($id, $locale) */ public function getId($object) { + /** @var string */ return $object->getResource()->getId(); } @@ -153,9 +154,12 @@ public function serialize($object) */ public function deserialize($serializedObject, $objectClass) { + /** @var mixed[] $data */ $data = \json_decode($serializedObject, true); + /** @var string|null $id */ $id = $data['id'] ?? null; + /** @var string|null $locale */ $locale = $data['locale'] ?? null; if (!$id || !$locale) { diff --git a/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php b/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php index 8d08abcf..fe384b96 100644 --- a/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php +++ b/Content/Infrastructure/Sulu/Search/ContentReindexProvider.php @@ -80,6 +80,7 @@ public function provide($classFqn, $offset, $maxResults) ->setFirstResult($offset) ->setMaxResults($maxResults); + /** @var ContentRichEntityInterface[] */ return $queryBuilder->getQuery()->execute(); } @@ -99,6 +100,7 @@ public function getCount($classFqn) ->from($this->contentRichEntityClass, 'contentRichEntity') ->select('COUNT(contentRichEntity)'); + /** @var int */ return $queryBuilder->getQuery()->getSingleScalarResult(); } diff --git a/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php b/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php index 39e243a6..c7f575eb 100644 --- a/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php +++ b/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php @@ -119,6 +119,7 @@ public function build($page, $scheme, $host): array $mainRoute = $entityRoutes[$defaultLocale]; unset($entityRoutes[$defaultLocale]); } else { + /** @var RouteInterface $mainRoute */ $mainRoute = \array_shift($entityRoutes); } @@ -168,7 +169,7 @@ public function getMaxPage($scheme, $host): int /** * @param RouteInterface[] $routes * - * @return mixed[] + * @return array> */ protected function groupRoutesByEntityId(array $routes): array { @@ -188,7 +189,7 @@ protected function groupRoutesByEntityId(array $routes): array } /** - * @return mixed[] + * @return RouteInterface[] */ protected function getRoutes(int $limit, int $offset): array { @@ -201,9 +202,8 @@ protected function getRoutes(int $limit, int $offset): array ->setFirstResult($offset) ->setMaxResults($limit); - $result = $queryBuilder->getQuery()->getResult(); - - return $result; + /** @var RouteInterface[] */ + return $queryBuilder->getQuery()->getResult(); } protected function createRoutesQueryBuilder(): QueryBuilder diff --git a/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php b/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php index 9ac7d6bc..eafc4b58 100644 --- a/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php +++ b/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php @@ -74,9 +74,9 @@ public function __construct( /** * @param array $filters - * @param mixed|null $page - * @param mixed|null $pageSize - * @param mixed|null $limit + * @param string|int|null $page + * @param string|int|null $pageSize + * @param string|int|null $limit * @param string $locale * @param array $options * @@ -124,7 +124,7 @@ function(ContentRichEntityInterface $contentRichEntity) use ($locale, $showUnpub * @param array $filters * @param array $options * - * @return mixed[] entity ids + * @return array entity ids */ protected function findEntityIdsByFilters( array $filters, @@ -139,7 +139,8 @@ protected function findEntityIdsByFilters( $queryBuilder = $this->createEntityIdsQueryBuilder($locale); if (!empty($categories = $filters['categories'] ?? [])) { - $categoryOperator = (string) ($filters['categoryOperator'] ?? 'OR'); + /** @var mixed[] $categories */ + $categoryOperator = (string) ($filters['categoryOperator'] ?? 'OR'); // @phpstan-ignore-line $parameters = \array_merge( $parameters, @@ -148,7 +149,8 @@ protected function findEntityIdsByFilters( } if (!empty($websiteCategories = $filters['websiteCategories'] ?? [])) { - $websiteCategoryOperator = (string) ($filters['websiteCategoriesOperator'] ?? 'OR'); + /** @var mixed[] $websiteCategories */ + $websiteCategoryOperator = (string) ($filters['websiteCategoriesOperator'] ?? 'OR'); // @phpstan-ignore-line $parameters = \array_merge( $parameters, @@ -157,7 +159,8 @@ protected function findEntityIdsByFilters( } if (!empty($tags = $filters['tags'] ?? [])) { - $tagOperator = (string) ($filters['tagOperator'] ?? 'OR'); + /** @var mixed[] $tags */ + $tagOperator = (string) ($filters['tagOperator'] ?? 'OR'); // @phpstan-ignore-line $parameters = \array_merge( $parameters, @@ -166,7 +169,8 @@ protected function findEntityIdsByFilters( } if (!empty($websiteTags = $filters['websiteTags'] ?? [])) { - $websiteTagOperator = (string) ($filters['websiteTagsOperator'] ?? 'OR'); + /** @var mixed[] $websiteTags */ + $websiteTagOperator = (string) ($filters['websiteTagsOperator'] ?? 'OR'); // @phpstan-ignore-line $parameters = \array_merge( $parameters, @@ -175,6 +179,7 @@ protected function findEntityIdsByFilters( } if (!empty($types = $filters['types'] ?? [])) { + /** @var mixed[] $types */ $parameters = \array_merge( $parameters, $this->addTypeFilter($queryBuilder, $types, 'adminTypes') @@ -192,23 +197,26 @@ protected function findEntityIdsByFilters( } if ($dataSource = $filters['dataSource'] ?? null) { + $dataSource = (string) $dataSource; // @phpstan-ignore-line + // TODO FIXME add testcase for this // @codeCoverageIgnoreStart $includeSubFolders = (bool) ($filters['includeSubFolders'] ?? false); $parameters = \array_merge( $parameters, - $this->addDatasourceFilter($queryBuilder, (string) $dataSource, $includeSubFolders, 'datasource') + $this->addDatasourceFilter($queryBuilder, $dataSource, $includeSubFolders, 'datasource') ); // @codeCoverageIgnoreEnd } if ($sortColumn = $filters['sortBy'] ?? null) { - $sortMethod = (string) ($filters['sortMethod'] ?? 'asc'); + $sortColumn = (string) $sortColumn; // @phpstan-ignore-line + $sortMethod = (string) ($filters['sortMethod'] ?? 'asc'); // @phpstan-ignore-line $parameters = \array_merge( $parameters, - $this->setSortBy($queryBuilder, (string) $sortColumn, $sortMethod) + $this->setSortBy($queryBuilder, $sortColumn, $sortMethod) ); } @@ -475,7 +483,7 @@ protected function createEntityIdsQueryBuilder(string $locale): QueryBuilder } /** - * @param mixed[] $ids + * @param array $ids * * @return ContentRichEntityInterface[] */ @@ -483,6 +491,7 @@ protected function findEntitiesByIds(array $ids): array { $entityIdentifierFieldName = $this->getEntityIdentifierFieldName(); + /** @var ContentRichEntityInterface[] $entities */ $entities = $this->entityManager->createQueryBuilder() ->select(self::CONTENT_RICH_ENTITY_ALIAS) ->from($this->contentRichEntityClass, self::CONTENT_RICH_ENTITY_ALIAS) diff --git a/Content/Infrastructure/Sulu/Structure/ContentDocument.php b/Content/Infrastructure/Sulu/Structure/ContentDocument.php index d5fa0954..01043396 100644 --- a/Content/Infrastructure/Sulu/Structure/ContentDocument.php +++ b/Content/Infrastructure/Sulu/Structure/ContentDocument.php @@ -139,7 +139,7 @@ public function setStructureType($structureType): void public function getStructure() { - return null; + return null; // @phpstan-ignore-line } protected function createReadOnlyException(string $method): \BadMethodCallException diff --git a/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php b/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php index 152fb60f..fd41a0e4 100644 --- a/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php +++ b/Content/Infrastructure/Sulu/Structure/ContentStructureBridge.php @@ -130,8 +130,18 @@ public function getController(): ?string return $this->structure->getController(); } - public function getCacheLifeTime() + /** + * @return array{ + * type: string, + * value: string, + * } + */ + public function getCacheLifeTime(): array { + /** @var array{ + * type: string, + * value: string, + * } */ return $this->structure->getCacheLifetime(); } @@ -422,7 +432,7 @@ public function getOriginTemplate(): ?string } /** - * @param mixed $name + * @param string $name * * @return mixed */ diff --git a/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactory.php b/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactory.php index 3a7cc152..f1e01935 100644 --- a/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactory.php +++ b/Content/Infrastructure/Sulu/Structure/ContentStructureBridgeFactory.php @@ -53,7 +53,7 @@ public function getBridge(TemplateInterface $object, $id, string $locale): Conte $structureMetadata, $this->propertyFactory, $object, - $id, + $id, // @phpstan-ignore-line $locale ); } diff --git a/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php b/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php index 408fca14..717dfb16 100644 --- a/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php +++ b/Content/Infrastructure/Sulu/Structure/RoutableStructureInterface.php @@ -13,14 +13,16 @@ namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure; -if (interface_exists(\Sulu\Component\Content\Compat\RoutableStructureInterface::class)) { +use Sulu\Component\Content\Compat\RoutableStructureInterface as SuluRoutableStructureInterface; + +if (interface_exists(SuluRoutableStructureInterface::class)) { /** * @deprecated will be removed, as soon as the ArticleBundle rises the minimum requirement of sulu to a version, * where this interface exists * * @internal */ - interface RoutableStructureInterface extends \Sulu\Component\Content\Compat\RoutableStructureInterface + interface RoutableStructureInterface extends SuluRoutableStructureInterface { } } else { diff --git a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php index f6f1afd4..9c2d5c02 100644 --- a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php +++ b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php @@ -81,7 +81,7 @@ public function __construct( } /** - * @param mixed[] $ids + * @param array $ids * @param string $locale * * @return Teaser[] @@ -125,6 +125,9 @@ protected function createTeaser(DimensionContentInterface $dimensionContent, arr return null; } + /** @var string|int $id */ + $id = $dimensionContent->getResource()->getId(); + /** @var string $title */ $title = $this->getTitle($dimensionContent, $data); @@ -138,7 +141,7 @@ protected function createTeaser(DimensionContentInterface $dimensionContent, arr $mediaId = $this->getMediaId($dimensionContent, $data); return new Teaser( - $dimensionContent->getResource()->getId(), + $id, $this->getResourceKey(), $locale, $title, @@ -195,6 +198,7 @@ protected function getUrl(DimensionContentInterface $dimensionContent, array $da foreach ($metadata->getProperties() as $property) { if ('route' === $property->getType()) { + /** @var string|null */ return $dimensionContent->getTemplateData()[$property->getName()] ?? null; } } @@ -227,6 +231,7 @@ protected function getDescription(DimensionContentInterface $dimensionContent, a } } + /** @var string|null */ return $data['description'] ?? null; } @@ -241,6 +246,7 @@ protected function getMoreText(DimensionContentInterface $dimensionContent, arra } } + /** @var string|null */ return $data['more'] ?? $data['moreText'] ?? null; } @@ -252,6 +258,7 @@ protected function getMediaId(DimensionContentInterface $dimensionContent, array if ($dimensionContent instanceof ExcerptInterface) { if ($excerptImage = $dimensionContent->getExcerptImage()) { // TODO FIXME create unit test for this + /** @var int|null */ return $excerptImage['id'] ?? null; // @codeCoverageIgnore } } @@ -270,7 +277,7 @@ protected function getAttributes(DimensionContentInterface $dimensionContent, ar } /** - * @param mixed[] $ids + * @param array $ids * * @return ContentRichEntityInterface[] */ @@ -279,6 +286,7 @@ protected function findEntitiesByIds(array $ids): array $entityIdField = $this->getEntityIdField(); $classMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass); + /** @var ContentRichEntityInterface[] $entities */ $entities = $this->entityManager->createQueryBuilder() ->select(self::CONTENT_RICH_ENTITY_ALIAS) ->from($this->contentRichEntityClass, self::CONTENT_RICH_ENTITY_ALIAS) diff --git a/DependencyInjection/Compiler/SettingsFormPass.php b/DependencyInjection/Compiler/SettingsFormPass.php index baa694ea..2fdf8aff 100644 --- a/DependencyInjection/Compiler/SettingsFormPass.php +++ b/DependencyInjection/Compiler/SettingsFormPass.php @@ -74,7 +74,7 @@ public function process(ContainerBuilder $container): void } \uasort($settingsForms, static function($a, $b) { - return $b['priority'] ?? 0 <=> $a['priority'] ?? 0; + return $b['priority'] ?? 0 <=> $a['priority'] ?? 0; // @phpstan-ignore-line }); $container->setParameter('sulu_content.content_settings_forms', $settingsForms); diff --git a/DependencyInjection/SuluContentExtension.php b/DependencyInjection/SuluContentExtension.php index 96eb45bf..4133f3b7 100644 --- a/DependencyInjection/SuluContentExtension.php +++ b/DependencyInjection/SuluContentExtension.php @@ -52,7 +52,7 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('services.xml'); $loader->load('form-visitor.xml'); - if ($container->hasParameter('kernel.bundles')) { + if ($container->hasParameter('kernel.bundles')) { // @phpstan-ignore-line // TODO FIXME add test here // @codeCoverageIgnoreStart /** @var string[] $bundles */ diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 2275591c..ea0d064f 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -90,10 +90,7 @@ - - - - + diff --git a/Tests/Application/ExampleTestBundle/DependencyInjection/ExampleTestExtension.php b/Tests/Application/ExampleTestBundle/DependencyInjection/ExampleTestExtension.php index 23990293..da7ef2c8 100644 --- a/Tests/Application/ExampleTestBundle/DependencyInjection/ExampleTestExtension.php +++ b/Tests/Application/ExampleTestBundle/DependencyInjection/ExampleTestExtension.php @@ -87,7 +87,7 @@ public function prepend(ContainerBuilder $container): void $suluSearchConfigs = $container->getExtensionConfig('sulu_search'); foreach ($suluSearchConfigs as $suluSearchConfig) { - if (isset($suluSearchConfig['website']['indexes'])) { + if (isset($suluSearchConfig['website']['indexes'])) { // @phpstan-ignore-line $container->prependExtensionConfig( 'sulu_search', [ diff --git a/Tests/Application/ExampleTestBundle/Entity/Example.php b/Tests/Application/ExampleTestBundle/Entity/Example.php index 73a842f1..68f589ad 100644 --- a/Tests/Application/ExampleTestBundle/Entity/Example.php +++ b/Tests/Application/ExampleTestBundle/Entity/Example.php @@ -25,12 +25,12 @@ class Example implements ContentRichEntityInterface public const TEMPLATE_TYPE = 'example'; /** - * @var mixed + * @var int */ public $id; /** - * @return mixed + * @return int */ public function getId() { diff --git a/Tests/Application/ExampleTestBundle/Repository/ExampleRepository.php b/Tests/Application/ExampleTestBundle/Repository/ExampleRepository.php index f5ec6c79..4d4f8c10 100644 --- a/Tests/Application/ExampleTestBundle/Repository/ExampleRepository.php +++ b/Tests/Application/ExampleTestBundle/Repository/ExampleRepository.php @@ -96,7 +96,7 @@ public function __construct( * example_admin?: bool, * example_website?: bool, * with-example-content?: array, - * }|array $selects + * } $selects * * @throws ExampleNotFoundException */ @@ -125,7 +125,7 @@ public function getOneBy(array $filters, array $selects = []): Example * example_admin?: bool, * example_website?: bool, * with-example-content?: array, - * }|array $selects + * } $selects */ public function findOneBy(array $filters, array $selects = []): ?Example { @@ -163,7 +163,7 @@ public function countBy(array $filters = []): int // instead of that the developer need to take that into account // in there call of the countBy method. unset($filters['page']); // @phpstan-ignore-line - unset($filters['limit']); + unset($filters['limit']); // @phpstan-ignore-line /** * @see https://github.com/phpstan/phpstan/issues/5223https://github.com/phpstan/phpstan/issues/5223 @@ -185,7 +185,7 @@ public function countBy(array $filters = []): int $queryBuilder->select('COUNT(DISTINCT example.id)'); - return (int) $queryBuilder->getQuery()->getSingleScalarResult(); + return (int) $queryBuilder->getQuery()->getSingleScalarResult(); // @phpstan-ignore-line } /** @@ -211,8 +211,8 @@ public function countBy(array $filters = []): int * @param array{ * example_admin?: bool, * example_website?: bool, - * with-example-content?: bool|array, - * }|array $selects + * with-example-content?: array, + * } $selects * * @return \Generator */ @@ -259,7 +259,11 @@ public function remove(Example $example): void * id?: 'asc'|'desc', * title?: 'asc'|'desc', * } $sortBy - * @param array $selects + * @param array{ + * example_admin?: bool, + * example_website?: bool, + * with-example-content?: array, + * } $selects */ private function createQueryBuilder(array $filters, array $sortBy = [], array $selects = []): QueryBuilder { @@ -315,7 +319,7 @@ private function createQueryBuilder(array $filters, array $sortBy = [], array $s if ($selects['with-example-content'] ?? null) { /** @var array $contentSelects */ - $contentSelects = $selects['with-example-content'] ?? []; + $contentSelects = $selects['with-example-content']; $queryBuilder->leftJoin( 'example.dimensionContents', diff --git a/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php b/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php index a18739ec..b8eb25f3 100644 --- a/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php +++ b/Tests/Application/ExampleTestBundle/Teaser/ExampleTeaserProvider.php @@ -56,7 +56,9 @@ public function getConfiguration(): TeaserConfiguration protected function getDescription(DimensionContentInterface $dimensionContent, array $data): ?string { - $article = \strip_tags($data['article'] ?? ''); + /** @var string $article */ + $article = $data['article'] ?? ''; + $article = \strip_tags($article); return $article ?: parent::getDescription($dimensionContent, $data); } diff --git a/Tests/Functional/Content/Infrastructure/Doctrine/DimensionContentRepositoryTest.php b/Tests/Functional/Content/Infrastructure/Doctrine/DimensionContentRepositoryTest.php index bce579c4..f7330774 100644 --- a/Tests/Functional/Content/Infrastructure/Doctrine/DimensionContentRepositoryTest.php +++ b/Tests/Functional/Content/Infrastructure/Doctrine/DimensionContentRepositoryTest.php @@ -50,12 +50,15 @@ public function testLoadExistAll(): void // assert result $this->assertCount(2, $dimensionContentCollection); + /** @var ExampleDimensionContent[] $dimensionContents */ + $dimensionContents = \iterator_to_array($dimensionContentCollection); + $this->assertSame([ $dimensionContent1->getId(), $dimensionContent2->getId(), ], \array_map(function(ExampleDimensionContent $dimensionContent) { return $dimensionContent->getId(); - }, \iterator_to_array($dimensionContentCollection))); + }, $dimensionContents)); } public function testLoadOneNotExist(): void @@ -74,11 +77,14 @@ public function testLoadOneNotExist(): void // assert result $this->assertCount(1, $dimensionContentCollection); + /** @var ExampleDimensionContent[] $dimensionContents */ + $dimensionContents = \iterator_to_array($dimensionContentCollection); + $this->assertSame([ $dimensionContent1->getId(), ], \array_map(function(ExampleDimensionContent $dimensionContent) { return $dimensionContent->getId(); - }, \iterator_to_array($dimensionContentCollection))); + }, $dimensionContents)); } public function testLoadExistOrderedDifferent(): void @@ -99,12 +105,15 @@ public function testLoadExistOrderedDifferent(): void // assert result $this->assertCount(2, $dimensionContentCollection); + /** @var ExampleDimensionContent[] $dimensionContents */ + $dimensionContents = \iterator_to_array($dimensionContentCollection); + $this->assertSame([ $dimensionContent1->getId(), $dimensionContent2->getId(), // Dimension 2 should be the last one in this case ], \array_map(function(ExampleDimensionContent $dimensionContent) { return $dimensionContent->getId(); - }, \iterator_to_array($dimensionContentCollection))); + }, $dimensionContents)); } private function createContentRichEntity(): Example @@ -120,8 +129,11 @@ private function createContentRichEntity(): Example */ private function createContentDimension(Example $example, array $dimensionAttributes = []): ExampleDimensionContent { + /** @var string $stage */ + $stage = $dimensionAttributes['stage'] ?? DimensionContentInterface::STAGE_DRAFT; + $exampleDimension = new ExampleDimensionContent($example); - $exampleDimension->setStage($dimensionAttributes['stage'] ?? DimensionContentInterface::STAGE_DRAFT); + $exampleDimension->setStage($stage); $exampleDimension->setLocale($dimensionAttributes['locale'] ?? null); $this->getEntityManager()->persist($exampleDimension); diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php index b6b0d626..a0e27398 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentReindexProviderTest.php @@ -26,11 +26,6 @@ class ContentReindexProviderTest extends SuluTestCase { use CreateExampleTrait; - /** - * @var ContentManagerInterface - */ - private $contentManager; - /** * @var ContentReindexProvider */ @@ -50,7 +45,7 @@ public static function setUpBeforeClass(): void { static::purgeDatabase(); - static::$example1 = static::createExample( + self::$example1 = static::createExample( [ 'en' => [ 'draft' => [ @@ -65,7 +60,7 @@ public static function setUpBeforeClass(): void ] ); - static::$example2 = static::createExample( + self::$example2 = static::createExample( [ 'en' => [ 'draft' => [ @@ -80,7 +75,6 @@ public static function setUpBeforeClass(): void protected function setUp(): void { - $this->contentManager = $this->getContainer()->get('sulu_content.content_manager'); $this->reindexProvider = $this->getContainer()->get('example_test.example_reindex_provider'); } @@ -88,8 +82,8 @@ public function testProvide(): void { $examples = $this->reindexProvider->provide(ExampleDimensionContent::class, 0, 10); - $this->assertContains(static::$example1, $examples); - $this->assertContains(static::$example2, $examples); + $this->assertContains(self::$example1, $examples); + $this->assertContains(self::$example2, $examples); $this->assertCount(2, $examples); } @@ -117,7 +111,7 @@ public function testGetClassFqns(): void public function testGetLocalesForObject(): void { - $locales = $this->reindexProvider->getLocalesForObject(static::$example1); + $locales = $this->reindexProvider->getLocalesForObject(self::$example1); $this->assertSame(['en', 'de'], $locales); } @@ -136,14 +130,14 @@ public function testGetLocalesForObjectWebsite(): void $property->setAccessible(true); $property->setValue($this->reindexProvider, SuluKernel::CONTEXT_WEBSITE); - $locales = $this->reindexProvider->getLocalesForObject(static::$example1); + $locales = $this->reindexProvider->getLocalesForObject(self::$example1); $this->assertSame(['de'], $locales); } public function testTranslateObject(): void { - $translatedObject = $this->reindexProvider->translateObject(static::$example1, 'en'); + $translatedObject = $this->reindexProvider->translateObject(self::$example1, 'en'); $this->assertInstanceOf(DimensionContentInterface::class, $translatedObject); @@ -165,7 +159,7 @@ public function testTranslateObjectWebsite(): void $property->setAccessible(true); $property->setValue($this->reindexProvider, SuluKernel::CONTEXT_WEBSITE); - $translatedObject = $this->reindexProvider->translateObject(static::$example1, 'de'); + $translatedObject = $this->reindexProvider->translateObject(self::$example1, 'de'); $this->assertInstanceOf(DimensionContentInterface::class, $translatedObject); @@ -188,7 +182,7 @@ public function testTranslateObjectWebsiteNotPublished(): void $property->setValue($this->reindexProvider, SuluKernel::CONTEXT_WEBSITE); $this->assertNull( - $this->reindexProvider->translateObject(static::$example1, 'en') + $this->reindexProvider->translateObject(self::$example1, 'en') ); } diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php index e9404fb3..07d49256 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Search/ContentSearchMetadataProviderTest.php @@ -51,7 +51,7 @@ public static function setUpBeforeClass(): void static::purgeDatabase(); parent::setUpBeforeClass(); - static::$example1 = static::createExample([ + self::$example1 = static::createExample([ 'en' => [ 'draft' => [ 'title' => 'example-1', @@ -71,7 +71,7 @@ protected function setUp(): void public function testGetMetadataForObject(): void { - $dimensionContent = $this->contentManager->resolve(static::$example1, [ + $dimensionContent = $this->contentManager->resolve(self::$example1, [ 'stage' => DimensionContentInterface::STAGE_DRAFT, 'locale' => 'en', ]); @@ -93,7 +93,7 @@ public function testGetMetadataForObjectNotMerged(): void { $this->assertNull( $this->searchMetadataProvider->getMetadataForObject( - (object) static::$example1->getDimensionContents()->first() + (object) self::$example1->getDimensionContents()->first() ) ); } @@ -111,7 +111,7 @@ public function testGetAllMetadata(): void public function testGetMetadataForDocument(): void { - $dimensionContent = $this->contentManager->resolve(static::$example1, [ + $dimensionContent = $this->contentManager->resolve(self::$example1, [ 'stage' => DimensionContentInterface::STAGE_DRAFT, 'locale' => 'en', ]); diff --git a/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php index 70baf04f..8e6e1e1f 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php @@ -23,6 +23,7 @@ use Sulu\Bundle\TestBundle\Testing\SuluTestCase; use Sulu\Component\SmartContent\ArrayAccessItem; use Sulu\Component\SmartContent\DataProviderResult; +use Sulu\Component\SmartContent\ResourceItemInterface; class ContentDataProviderTest extends SuluTestCase { @@ -71,7 +72,7 @@ public static function setUpBeforeClass(): void static::purgeDatabase(); parent::setUpBeforeClass(); - static::$categoryFoo = static::createCategory([ + self::$categoryFoo = static::createCategory([ 'en' => [ 'title' => 'Foo', ], @@ -80,27 +81,27 @@ public static function setUpBeforeClass(): void ], ]); - static::$categoryBar = static::createCategory([ + self::$categoryBar = static::createCategory([ 'en' => [ 'title' => 'Bar', ], ]); - static::$categoryBaz = static::createCategory([ + self::$categoryBaz = static::createCategory([ 'de' => [ 'title' => 'Baz', ], ]); - static::$tagA = static::createTag([ + self::$tagA = static::createTag([ 'name' => 'tagA', ]); - static::$tagB = static::createTag([ + self::$tagB = static::createTag([ 'name' => 'tagB', ]); - static::$tagC = static::createTag([ + self::$tagC = static::createTag([ 'name' => 'tagC', ]); @@ -117,12 +118,12 @@ public static function setUpBeforeClass(): void 'draft' => [ 'title' => 'example without categories without tags draft', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), ], 'excerptTags' => [ - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], 'live' => [ @@ -137,7 +138,7 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with some categories without tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), + self::$categoryFoo->getId(), ], ], ], @@ -145,7 +146,7 @@ public static function setUpBeforeClass(): void 'draft' => [ 'title' => 'example with some categories without tags unpublished', 'excerptCategories' => [ - static::$categoryFoo->getId(), + self::$categoryFoo->getId(), ], 'excerptTags' => [], ], @@ -158,9 +159,9 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with all categories without tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], ], ], @@ -168,9 +169,9 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with all categories without tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'excerptTags' => [], ], @@ -183,7 +184,7 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example without categories with some tags', 'excerptTags' => [ - static::$tagA->getName(), + self::$tagA->getName(), ], ], ], @@ -191,7 +192,7 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example without categories with some tags', 'excerptTags' => [ - static::$tagA->getName(), + self::$tagA->getName(), ], ], ], @@ -203,9 +204,9 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example without categories with all tags', 'excerptTags' => [ - static::$tagA->getName(), - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagA->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], ], @@ -213,9 +214,9 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example without categories with all tags', 'excerptTags' => [ - static::$tagA->getName(), - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagA->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], ], @@ -227,10 +228,10 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with some categories with some tags', 'excerptCategories' => [ - static::$categoryBar->getId(), + self::$categoryBar->getId(), ], 'excerptTags' => [ - static::$tagB->getName(), + self::$tagB->getName(), ], ], ], @@ -238,10 +239,10 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with some categories with some tags', 'excerptCategories' => [ - static::$categoryBar->getId(), + self::$categoryBar->getId(), ], 'excerptTags' => [ - static::$tagB->getName(), + self::$tagB->getName(), ], ], ], @@ -253,14 +254,14 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with all categories with all tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'excerptTags' => [ - static::$tagA->getName(), - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagA->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], ], @@ -268,14 +269,14 @@ public static function setUpBeforeClass(): void 'live' => [ 'title' => 'example with all categories with all tags', 'excerptCategories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'excerptTags' => [ - static::$tagA->getName(), - static::$tagB->getName(), - static::$tagC->getName(), + self::$tagA->getName(), + self::$tagB->getName(), + self::$tagC->getName(), ], ], ], @@ -302,7 +303,7 @@ protected function setUp(): void public function testResolveDataItems(): void { foreach ($this->filters() as $dataset) { - list($name, $locale, $page, $pageSize, $limit, $filters, $expectedCount, $expectedHasNextPage) = $dataset; + [$name, $locale, $page, $pageSize, $limit, $filters, $expectedCount, $expectedHasNextPage] = $dataset; /** @var string $name */ /** @var string $locale */ @@ -389,7 +390,7 @@ public function testResolveResourceItemsSnapshot(): void /** * This method can't be a phpunit dataProvider, because then it wouldn't be possible to access the categories, because they don't exist at the time a dataProvider is called. * - * @return mixed[] + * @return array */ public function filters(): array { @@ -442,9 +443,9 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'categoryOperator' => 'OR', ], @@ -459,9 +460,9 @@ public function filters(): array null, [ 'tags' => [ - static::$tagA, - static::$tagB, - static::$tagC, + self::$tagA, + self::$tagB, + self::$tagC, ], 'tagOperator' => 'OR', ], @@ -476,15 +477,15 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'categoryOperator' => 'OR', 'tags' => [ - static::$tagA, - static::$tagB, - static::$tagC, + self::$tagA, + self::$tagB, + self::$tagC, ], 'tagOperator' => 'OR', ], @@ -499,12 +500,12 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), + self::$categoryFoo->getId(), ], 'categoryOperator' => 'AND', 'websiteCategories' => [ - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'websiteCategoriesOperator' => 'OR', ], @@ -519,11 +520,11 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), + self::$categoryFoo->getId(), ], 'websiteCategories' => [ - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'categoryOperator' => 'AND', 'websiteCategoriesOperator' => 'AND', @@ -539,11 +540,11 @@ public function filters(): array null, [ 'tags' => [ - static::$tagA, - static::$tagB, + self::$tagA, + self::$tagB, ], 'websiteTags' => [ - static::$tagC, + self::$tagC, ], 'tagOperator' => 'AND', 'websiteTagsOperator' => 'AND', @@ -559,15 +560,15 @@ public function filters(): array null, [ 'categories' => [ - static::$categoryFoo->getId(), - static::$categoryBar->getId(), - static::$categoryBaz->getId(), + self::$categoryFoo->getId(), + self::$categoryBar->getId(), + self::$categoryBaz->getId(), ], 'categoryOperator' => 'AND', 'tags' => [ - static::$tagA, - static::$tagB, - static::$tagC, + self::$tagA, + self::$tagB, + self::$tagC, ], 'tagOperator' => 'AND', ], @@ -611,6 +612,9 @@ public function filters(): array */ private function mapDataProviderResult(DataProviderResult $dataProviderResult): array { + /** @var ArrayAccessItem[] $items */ + $items = $dataProviderResult->getItems(); + return \array_map(function(ArrayAccessItem $item) { return [ 'id' => $item->getId(), @@ -621,6 +625,6 @@ private function mapDataProviderResult(DataProviderResult $dataProviderResult): 'title' => $item['title'], 'url' => $item['url'], ]; - }, $dataProviderResult->getItems()); + }, $items); } } diff --git a/Tests/Functional/Content/Infrastructure/Sulu/Teaser/ContentTeaserProviderTest.php b/Tests/Functional/Content/Infrastructure/Sulu/Teaser/ContentTeaserProviderTest.php index cd068be1..6bfc4110 100644 --- a/Tests/Functional/Content/Infrastructure/Sulu/Teaser/ContentTeaserProviderTest.php +++ b/Tests/Functional/Content/Infrastructure/Sulu/Teaser/ContentTeaserProviderTest.php @@ -30,15 +30,10 @@ class ContentTeaserProviderTest extends WebsiteTestCase private $exampleTeaserProvider; /** - * @var mixed[] + * @var int[] */ private static $exampleIds = []; - /** - * @var mixed - */ - private static $exampleIdNoRoute; - public static function setUpBeforeClass(): void { static::purgeDatabase(); @@ -109,11 +104,11 @@ public static function setUpBeforeClass(): void static::getEntityManager()->flush(); - static::$exampleIds[] = $example1->getId(); - static::$exampleIds[] = $example2->getId(); - static::$exampleIds[] = $example3->getId(); - static::$exampleIds[] = $example4->getId(); - static::$exampleIds[] = $example5->getId(); + self::$exampleIds[] = $example1->getId(); + self::$exampleIds[] = $example2->getId(); + self::$exampleIds[] = $example3->getId(); + self::$exampleIds[] = $example4->getId(); + self::$exampleIds[] = $example5->getId(); } protected function setUp(): void @@ -130,7 +125,7 @@ public function testEmpty(): void public function testFindDE(): void { - $teasers = $this->exampleTeaserProvider->find(static::$exampleIds, 'de'); + $teasers = $this->exampleTeaserProvider->find(self::$exampleIds, 'de'); $teasers = $this->mapTeasers($teasers); @@ -139,7 +134,7 @@ public function testFindDE(): void public function testFindEN(): void { - $teasers = $this->exampleTeaserProvider->find(static::$exampleIds, 'en'); + $teasers = $this->exampleTeaserProvider->find(self::$exampleIds, 'en'); $teasers = $this->mapTeasers($teasers); diff --git a/Tests/Functional/Integration/ExampleControllerTest.php b/Tests/Functional/Integration/ExampleControllerTest.php index ef52c9fb..88ceb960 100644 --- a/Tests/Functional/Integration/ExampleControllerTest.php +++ b/Tests/Functional/Integration/ExampleControllerTest.php @@ -70,8 +70,10 @@ public function testPostPublish(): int ]) ?: null); $response = $this->client->getResponse(); + /** @var mixed[] $content */ $content = \json_decode((string) $response->getContent(), true); $id = $content['id'] ?? null; + $this->assertIsInt($id); $this->assertResponseSnapshot('example_post_publish.json', $response, 201); $this->assertNotSame('2020-05-08T00:00:00+00:00', $content['published']); @@ -144,7 +146,11 @@ public function testPost(): int $routeRepository = $this->getContainer()->get('sulu.repository.route'); $this->assertCount(0, $routeRepository->findAll()); - $id = \json_decode((string) $response->getContent(), true)['id'] ?? null; + /** @var mixed[] $content */ + $content = \json_decode((string) $response->getContent(), true); + $id = $content['id'] ?? null; + + $this->assertIsInt($id); return $id; } diff --git a/Tests/Traits/CreateCategoryTrait.php b/Tests/Traits/CreateCategoryTrait.php index 6e6b4745..a89da66b 100644 --- a/Tests/Traits/CreateCategoryTrait.php +++ b/Tests/Traits/CreateCategoryTrait.php @@ -21,7 +21,7 @@ trait CreateCategoryTrait { /** - * @param array{de?: mixed, en?: mixed} $dataSet + * @param array{de?: mixed[], en?: mixed[]} $dataSet */ protected static function createCategory(array $dataSet = []): CategoryInterface { @@ -30,11 +30,14 @@ protected static function createCategory(array $dataSet = []): CategoryInterface $category = new Category(); foreach ($dataSet as $locale => $data) { + /** @var string $title */ + $title = $data['title'] ?? ''; + $category->setDefaultLocale($locale); $translation = new CategoryTranslation(); $translation->setCategory($category); $translation->setLocale($locale); - $translation->setTranslation($data['title'] ?? null); + $translation->setTranslation($title); $category->addTranslation($translation); $entityManager->persist($translation); } diff --git a/Tests/Traits/CreateExampleTrait.php b/Tests/Traits/CreateExampleTrait.php index cc923078..f07fa83d 100644 --- a/Tests/Traits/CreateExampleTrait.php +++ b/Tests/Traits/CreateExampleTrait.php @@ -29,7 +29,7 @@ trait CreateExampleTrait { /** - * @param array{de?: mixed, en?: mixed} $dataSet + * @param array{de?: mixed[], en?: mixed[]} $dataSet * @param array{create_route?: bool} $options */ protected static function createExample(array $dataSet = [], array $options = []): Example @@ -145,10 +145,15 @@ protected static function createExample(array $dataSet = [], array $options = [] ); if ($options['create_route'] ?? false) { + /** @var string $path */ + $path = $draftLocalizedDimension->getTemplateData()['url']; + /** @var string $id */ + $id = $example->getId(); + $route = new Route(); $route->setLocale($locale); - $route->setPath($draftLocalizedDimension->getTemplateData()['url']); - $route->setEntityId($example->getId()); + $route->setPath($path); + $route->setEntityId($id); $route->setEntityClass(\get_class($example)); $entityManager->persist($route); diff --git a/Tests/Unit/Content/Infrastructure/Doctrine/RouteRemoverTest.php b/Tests/Unit/Content/Infrastructure/Doctrine/RouteRemoverTest.php index d1ba9358..dc06c464 100644 --- a/Tests/Unit/Content/Infrastructure/Doctrine/RouteRemoverTest.php +++ b/Tests/Unit/Content/Infrastructure/Doctrine/RouteRemoverTest.php @@ -44,10 +44,10 @@ public static function getResourceKey(): string private $routeRepository; /** - * @var mixed[] + * @var array */ private $routeMappings = [ - [ + ExampleDimensionContent::class => [ 'resource_key' => 'examples', 'entityClass' => ExampleDimensionContent::class, ], diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php index 8596ce70..a52a903b 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php @@ -47,7 +47,7 @@ class ContentViewBuilderFactoryTest extends TestCase { /** - * @param mixed[] $settingsForms + * @param array $settingsForms */ protected function createContentViewBuilder( ContentMetadataInspectorInterface $contentMetadataInspector, diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php index edaef41c..adfb91e5 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php @@ -76,19 +76,19 @@ public function testGetObject(int $id = 1, string $locale = 'de'): void $this->entityManager->createQueryBuilder()->willReturn($queryBuilder->reveal())->shouldBeCalledTimes(1); $queryBuilder->select(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $queryBuilder->from(Argument::type('string'), Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $queryBuilder->where(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $queryBuilder->setParameter(Argument::type('string'), Argument::any())->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $query = $this->prophesize(AbstractQuery::class); @@ -127,19 +127,19 @@ public function testGetObjectContentNotFound(int $id = 1, string $locale = 'de') $this->entityManager->createQueryBuilder()->willReturn($queryBuilder->reveal())->shouldBeCalledTimes(1); $queryBuilder->select(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $queryBuilder->from(Argument::type('string'), Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $queryBuilder->where(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $queryBuilder->setParameter(Argument::type('string'), Argument::any())->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $query = $this->prophesize(AbstractQuery::class); @@ -252,19 +252,19 @@ public function testDeserialize(): void $this->entityManager->createQueryBuilder()->willReturn($queryBuilder->reveal())->shouldBeCalledTimes(1); $queryBuilder->select(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $queryBuilder->from(Argument::type('string'), Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $queryBuilder->where(Argument::type('string'))->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $queryBuilder->setParameter(Argument::type('string'), Argument::any())->will(function() { - return \func_get_arg(\func_num_args() - 2); + return \func_get_arg(max(\func_num_args() - 2, 0)); })->shouldBeCalledTimes(1); $query = $this->prophesize(AbstractQuery::class); diff --git a/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php b/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php index ddf35423..641610e0 100644 --- a/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php +++ b/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php @@ -14,11 +14,14 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Mocks; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; /** * Trait for composing a class that wraps a DimensionContentInterface mock. * * @see MockWrapper to learn why this trait is needed. + * + * @property mixed $instance */ trait DimensionContentMockWrapperTrait { @@ -29,62 +32,98 @@ public static function getResourceKey(): string public function getLocale(): ?string { - return $this->instance->getLocale(); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + return $instance->getLocale(); } public function setLocale(?string $locale): void { - $this->instance->setLocale($locale); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + $instance->setLocale($locale); } public function getGhostLocale(): ?string { - return $this->instance->getGhostLocale(); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + return $instance->getGhostLocale(); } public function setGhostLocale(?string $ghostLocale): void { - $this->instance->setGhostLocale($ghostLocale); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + $instance->setGhostLocale($ghostLocale); } public function getAvailableLocales(): ?array { - return $this->instance->getAvailableLocales(); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + return $instance->getAvailableLocales(); } public function removeAvailableLocale(string $availableLocale): void { - $this->instance->removeAvailableLocale(); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + $instance->removeAvailableLocale($availableLocale); } public function addAvailableLocale(string $availableLocale): void { - $this->instance->addAvailableLocale($availableLocale); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + $instance->addAvailableLocale($availableLocale); } public function getStage(): string { - return $this->instance->getStage(); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + return $instance->getStage(); } - public function setStage(?string $stage): void + public function setStage(string $stage): void { - $this->instance->setStage($stage); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + $instance->setStage($stage); } public function getResource(): ContentRichEntityInterface { - return $this->instance->getResource(); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + return $instance->getResource(); } public function isMerged(): bool { - return $this->instance->isMerged(); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + return $instance->isMerged(); } public function markAsMerged(): void { - $this->instance->markAsMerged(); + /** @var DimensionContentInterface $instance */ + $instance = $this->instance; + + $instance->markAsMerged(); } public static function getDefaultDimensionAttributes(): array diff --git a/Tests/Unit/Mocks/RoutableMockWrapperTrait.php b/Tests/Unit/Mocks/RoutableMockWrapperTrait.php index 57e168d8..10a2bea1 100644 --- a/Tests/Unit/Mocks/RoutableMockWrapperTrait.php +++ b/Tests/Unit/Mocks/RoutableMockWrapperTrait.php @@ -13,10 +13,14 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Mocks; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface; + /** * Trait for composing a class that wraps a RoutableInterface mock. * * @see MockWrapper to learn why this trait is needed. + * + * @property mixed $instance */ trait RoutableMockWrapperTrait { @@ -27,11 +31,17 @@ public static function getResourceKey(): string public function getResourceId() { - return $this->instance->getResourceId(); + /** @var RoutableInterface $instance */ + $instance = $this->instance; + + return $instance->getResourceId(); } public function getLocale(): ?string { - return $this->instance->getLocale(); + /** @var RoutableInterface $instance */ + $instance = $this->instance; + + return $instance->getLocale(); } } diff --git a/Tests/Unit/Mocks/TemplateMockWrapperTrait.php b/Tests/Unit/Mocks/TemplateMockWrapperTrait.php index e8d184b3..24226724 100644 --- a/Tests/Unit/Mocks/TemplateMockWrapperTrait.php +++ b/Tests/Unit/Mocks/TemplateMockWrapperTrait.php @@ -13,10 +13,14 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Mocks; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface; + /** * Trait for composing a class that wraps a TemplateInterface mock. * * @see MockWrapper to learn why this trait is needed. + * + * @property mixed $instance */ trait TemplateMockWrapperTrait { @@ -27,21 +31,33 @@ public static function getTemplateType(): string public function getTemplateKey(): ?string { - return $this->instance->getTemplateKey(); + /** @var TemplateInterface $instance */ + $instance = $this->instance; + + return $instance->getTemplateKey(); } public function setTemplateKey(string $templateKey): void { - $this->instance->setTemplateKey($templateKey); + /** @var TemplateInterface $instance */ + $instance = $this->instance; + + $instance->setTemplateKey($templateKey); } public function getTemplateData(): array { - return $this->instance->getTemplateData(); + /** @var TemplateInterface $instance */ + $instance = $this->instance; + + return $instance->getTemplateData(); } public function setTemplateData(array $templateData): void { - $this->instance->setTemplateData($templateData); + /** @var TemplateInterface $instance */ + $instance = $this->instance; + + $instance->setTemplateData($templateData); } } diff --git a/Tests/Unit/Mocks/WorkflowMockWrapperTrait.php b/Tests/Unit/Mocks/WorkflowMockWrapperTrait.php index a7a6e203..e971a77a 100644 --- a/Tests/Unit/Mocks/WorkflowMockWrapperTrait.php +++ b/Tests/Unit/Mocks/WorkflowMockWrapperTrait.php @@ -13,10 +13,14 @@ namespace Sulu\Bundle\ContentBundle\Tests\Unit\Mocks; +use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; + /** * Trait for composing a class that wraps a WorkflowInterface mock. * * @see MockWrapper to learn why this trait is needed. + * + * @property mixed $instance */ trait WorkflowMockWrapperTrait { @@ -27,21 +31,33 @@ public static function getWorkflowName(): string public function getWorkflowPlace(): ?string { - return $this->instance->getWorkflowPlace(); + /** @var WorkflowInterface $instance */ + $instance = $this->instance; + + return $instance->getWorkflowPlace(); } public function setWorkflowPlace(?string $workflowPlace): void { - $this->instance->setWorkflowPlace($workflowPlace); + /** @var WorkflowInterface $instance */ + $instance = $this->instance; + + $instance->setWorkflowPlace($workflowPlace); } public function getWorkflowPublished(): ?\DateTimeImmutable { - return $this->instance->getWorkflowPublished(); + /** @var WorkflowInterface $instance */ + $instance = $this->instance; + + return $instance->getWorkflowPublished(); } public function setWorkflowPublished(?\DateTimeImmutable $workflowPublished): void { - $this->instance->setWorkflowPublished($workflowPublished); + /** @var WorkflowInterface $instance */ + $instance = $this->instance; + + $instance->setWorkflowPublished($workflowPublished); } } diff --git a/composer.json b/composer.json index 17bb19e8..d63dd098 100644 --- a/composer.json +++ b/composer.json @@ -42,15 +42,15 @@ "handcraftedinthealps/code-coverage-checker": "^0.2.1", "handcraftedinthealps/zendsearch": "^2.0", "jackalope/jackalope-doctrine-dbal": "^1.3.4", - "jangregor/phpstan-prophecy": "^0.8", + "jangregor/phpstan-prophecy": "^1.0", "matthiasnoback/symfony-config-test": "^4.0", "matthiasnoback/symfony-dependency-injection-test": "^4.0", "phpspec/prophecy": "^1.14", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-doctrine": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpstan/phpstan-symfony": "^0.12", - "phpstan/phpstan-webmozart-assert": "^0.12", + "phpstan/phpstan": "^1.8.10", + "phpstan/phpstan-doctrine": "^1.3", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-symfony": "^1.2", + "phpstan/phpstan-webmozart-assert": "^1.2", "qossmic/deptrac-shim": "^0.11.1 || ^0.23.0", "sulu/automation-bundle": "^2.0@dev", "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", @@ -60,7 +60,7 @@ "symfony/monolog-bundle": "^3.1", "symfony/phpunit-bridge": "^5.4 || ^6.0", "symfony/string": "^4.4 || ^5.4 || ^6.0", - "thecodingmachine/phpstan-strict-rules": "^0.12" + "thecodingmachine/phpstan-strict-rules": "^1.0" }, "conflict": { "doctrine/persistence": "1.3.2" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ea83dcf9..364905f7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,22 +1,2 @@ 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 - diff --git a/phpstan.neon b/phpstan.neon index 2607f4ae..985455d4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -12,7 +12,7 @@ parameters: paths: - . level: max - excludes_analyse: + excludePaths: - %currentWorkingDirectory%/DependencyInjection/Configuration.php - %currentWorkingDirectory%/vendor/* - %currentWorkingDirectory%/Tests/Application/Kernel.php @@ -25,7 +25,3 @@ parameters: objectManagerLoader: Tests/phpstan/object-manager.php bootstrapFiles: - vendor/bin/.phpunit/phpunit-8.5-0/vendor/autoload.php - ignoreErrors: - - message: "#^Method Sulu\\\\Bundle\\\\ContentBundle\\\\Content\\\\Infrastructure\\\\Sulu\\\\Structure\\\\ContentDocument\\:\\:getStructure\\(\\) should return Sulu\\\\Component\\\\Content\\\\Document\\\\Structure\\\\StructureInterface but returns null\\.$#" - count: 1 - path: Content/Infrastructure/Sulu/Structure/ContentDocument.php