Skip to content

Commit

Permalink
Fix PHPStan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed May 16, 2024
1 parent 5d476c6 commit 552648a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 29 deletions.
11 changes: 11 additions & 0 deletions Content/Application/ContentMerger/ContentMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -41,6 +42,13 @@ public function __construct(
$this->propertyAccessor = $propertyAccessor;
}

/**
* @template T of DimensionContentInterface
*
* @param DimensionContentCollectionInterface<T> $dimensionContentCollection
*
* @return T
*/
public function merge(DimensionContentCollectionInterface $dimensionContentCollection): DimensionContentInterface
{
if (!$dimensionContentCollection->count()) {
Expand All @@ -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();
}
Expand All @@ -69,6 +78,8 @@ public function merge(DimensionContentCollectionInterface $dimensionContentColle
}
}

Assert::notNull($mergedDimensionContent);

return $mergedDimensionContent;
}
}
4 changes: 2 additions & 2 deletions Content/Domain/Model/TemplateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function getTemplateKey(): ?string;
public function setTemplateKey(string $templateKey): void;

/**
* @return mixed[]
* @return array<string, mixed>
*/
public function getTemplateData(): array;

/**
* @param mixed[] $templateData
* @param array<string, mixed> $templateData
*/
public function setTemplateData(array $templateData): void;
}
5 changes: 4 additions & 1 deletion Content/Domain/Model/TemplateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait TemplateTrait
private $templateKey;

/**
* @var mixed[]
* @var array<string, mixed>
*/
private $templateData = [];

Expand All @@ -43,6 +43,9 @@ public function getTemplateData(): array
return $this->templateData;
}

/**
* @param array<string, mixed> $templateData
*/
public function setTemplateData(array $templateData): void
{
$this->templateData = $templateData;
Expand Down
8 changes: 7 additions & 1 deletion Content/Infrastructure/Sulu/Link/ContentLinkProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ 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;

if (!\is_string($title)) {
return null;
}

return $title;
}

protected function getEntityIdField(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 8 additions & 2 deletions Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected function createTeaser(DimensionContentInterface $dimensionContent, arr

/**
* @param B $dimensionContent
* @param mixed[] $data
* @param array<string, mixed> $data
*/
protected function getTitle(DimensionContentInterface $dimensionContent, array $data): ?string
{
Expand All @@ -172,7 +172,13 @@ protected function getTitle(DimensionContentInterface $dimensionContent, array $
}
}

return $data['title'] ?? $data['name'] ?? null;
$title = $data['title'] ?? $data['name'] ?? null;

if (!\is_string($title)) {
return null;
}

return $title;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ public function getTitle(): ?string
return $this->title;
}

/**
* @param array<string, mixed> $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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function testGetAlias(): void
/**
* @param SitemapUrl[] $sitemapEntries
*
* @return array<string, mixed>
* @return array<mixed>
*/
private function mapSitemapEntries(array $sitemapEntries): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 2 additions & 17 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\<string\\>\\|null given\\.$#"
message: "#^Parameter \\#1 \\$filters of method Sulu\\\\Component\\\\SmartContent\\\\Orm\\\\BaseDataProvider\\:\\:resolveDataItems\\(\\) expects array\\{dataSource\\?\\: int\\|string\\|null, sortMethod\\?\\: 'asc'\\|'desc', sortBy\\?\\: string, tags\\?\\: array\\<string\\>, tagOperator\\?\\: 'and'\\|'or', types\\?\\: array\\<string\\>, categories\\?\\: array\\<int\\>, categoryOperator\\?\\: 'and'\\|'or', \\.\\.\\.\\}, array given\\.$#"
count: 1
path: Tests/Application/ExampleTestBundle/Entity/ExampleDimensionContent.php

-
message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\<string\\>\\|null given\\.$#"
count: 2
path: Tests/Unit/Content/Application/ContentNormalizer/ContentNormalizerTest.php

-
message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\<string\\>\\|null given\\.$#"
count: 1
path: Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php

-
message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\<string\\>\\|null given\\.$#"
count: 3
path: Tests/Unit/Content/Infrastructure/Sulu/Admin/ContentViewBuilderFactoryTest.php
path: Tests/Functional/Content/Infrastructure/Sulu/SmartContent/ContentDataProviderTest.php

0 comments on commit 552648a

Please sign in to comment.