Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update phpstan and plugins #229

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,31 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: '7.2'
- php-version: '7.3'
coverage: false
dependency-versions: 'lowest'
tools: 'composer:v1'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

- php-version: '7.4'
coverage: true
coverage: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.0'
coverage: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.1'
coverage: true
dependency-versions: 'highest'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.2'
coverage: false
dependency-versions: 'highest'
env:
Expand All @@ -67,7 +70,7 @@ jobs:
php-version: ${{ matrix.php-version }}
extensions: ctype, iconv, mysql
coverage: pcov
tools: ${{ matrix.tools }}
tools: 'composer:v2'

- name: Install composer dependencies
uses: ramsey/composer-install@v2
Expand Down
18 changes: 18 additions & 0 deletions Content/Application/ContentCopier/ContentCopierInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
interface ContentCopierInterface
{
/**
* @template T of DimensionContentInterface
*
* @param ContentRichEntityInterface<T> $sourceContentRichEntity
* @param mixed[] $sourceDimensionAttributes
* @param ContentRichEntityInterface<T> $targetContentRichEntity
* @param mixed[] $targetDimensionAttributes
*
* @return T
*/
public function copy(
ContentRichEntityInterface $sourceContentRichEntity,
Expand All @@ -31,7 +37,13 @@ public function copy(
): DimensionContentInterface;

/**
* @template T of DimensionContentInterface
*
* @param DimensionContentCollectionInterface<T> $dimensionContentCollection
* @param ContentRichEntityInterface<T> $targetContentRichEntity
* @param mixed[] $targetDimensionAttributes
*
* @return T
*/
public function copyFromDimensionContentCollection(
DimensionContentCollectionInterface $dimensionContentCollection,
Expand All @@ -40,7 +52,13 @@ public function copyFromDimensionContentCollection(
): DimensionContentInterface;

/**
* @template T of DimensionContentInterface
*
* @param T $dimensionContent
* @param ContentRichEntityInterface<T> $targetContentRichEntity
* @param mixed[] $targetDimensionAttributes
*
* @return T
*/
public function copyFromDimensionContent(
DimensionContentInterface $dimensionContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;

interface ContentDataMapperInterface
{
/**
* @template T of DimensionContentInterface
*
* @param array<string, mixed> $data
* @param DimensionContentCollectionInterface<T> $dimensionContentCollection
*/
public function map(
array $data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;

interface DataMapperInterface
{
/**
* @template T of DimensionContentInterface
*
* @param array<string, mixed> $data
* @param DimensionContentCollectionInterface<T> $dimensionContentCollection
*/
public function map(
array $data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function map(
*/
private function setExcerptData(ExcerptInterface $dimensionContent, array $data): void
{
$dimensionContent->setExcerptTitle($data['excerptTitle'] ?? null);
$dimensionContent->setExcerptTitle($data['excerptTitle'] ?? null); // @phpstan-ignore-line TODO where validate this?
$dimensionContent->setExcerptDescription($data['excerptDescription'] ?? null);
$dimensionContent->setExcerptMore($data['excerptMore'] ?? null);
$dimensionContent->setExcerptImage($data['excerptImage'] ?? null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ public function map(
return; // @codeCoverageIgnore
}

$routePath = $data[$name] ?? null;
/** @var string $routePath */
$routePath = $data[$name] ?? '';
if (!$routePath) {
/** @var mixed $routeGenerationData */
/** @var mixed[] $routeGenerationData */
$routeGenerationData = \array_merge(
$data,
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function map(
*/
private function setSeoData(SeoInterface $dimensionContent, array $data): void
{
$dimensionContent->setSeoTitle($data['seoTitle'] ?? null);
$dimensionContent->setSeoTitle($data['seoTitle'] ?? null); // @phpstan-ignore-line TODO where validate this?
$dimensionContent->setSeoDescription($data['seoDescription'] ?? null);
$dimensionContent->setSeoKeywords($data['seoKeywords'] ?? null);
$dimensionContent->setSeoCanonicalUrl($data['seoCanonicalUrl'] ?? null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ public function map(
/**
* @param mixed[] $data
*
* @return mixed[]
* @return array{
* 0: mixed[],
* 1: mixed[],
* }
*/
private function getTemplateData(array $data, string $type, string $template): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private function setPublishedToLiveDimension(WorkflowInterface $object, array $d
return;
}

/** @var string|null $published */
$published = $data['published'] ?? null;

if (!$published) {
Expand Down
5 changes: 5 additions & 0 deletions Content/Application/ContentIndexer/ContentIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ public function deindexDimensionContent(DimensionContentInterface $dimensionCont
}

/**
* @template T of DimensionContentInterface
*
* @param ContentRichEntityInterface<T> $contentRichEntity
* @param mixed[] $dimensionAttributes
*
* @return T
*/
private function loadDimensionContent(
ContentRichEntityInterface $contentRichEntity,
Expand Down
17 changes: 16 additions & 1 deletion Content/Application/ContentIndexer/ContentIndexerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,32 @@
interface ContentIndexerInterface
{
/**
* @template T of DimensionContentInterface
*
* @param ContentRichEntityInterface<T> $contentRichEntity
* @param mixed[] $dimensionAttributes
*
* @return T
*/
public function index(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes): DimensionContentInterface;

/**
* @template T of DimensionContentInterface
*
* @param T $dimensionContent
*/
public function indexDimensionContent(DimensionContentInterface $dimensionContent): void;

/**
* @param mixed $id
* @param int|string $id
* @param mixed[] $dimensionAttributes
*/
public function deindex(string $resourceKey, $id, array $dimensionAttributes = []): void;

/**
* @template T of DimensionContentInterface
*
* @param T $dimensionContent
*/
public function deindexDimensionContent(DimensionContentInterface $dimensionContent): void;
}
32 changes: 31 additions & 1 deletion Content/Application/ContentManager/ContentManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,44 @@
interface ContentManagerInterface
{
/**
* @template T of DimensionContentInterface
*
* @param ContentRichEntityInterface<T> $contentRichEntity
* @param mixed[] $dimensionAttributes
*
* @return T
*/
public function resolve(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes): DimensionContentInterface;

/**
* @template T of DimensionContentInterface
*
* @param ContentRichEntityInterface<T> $contentRichEntity
* @param mixed[] $data
* @param mixed[] $dimensionAttributes
*
* @return T
*/
public function persist(ContentRichEntityInterface $contentRichEntity, array $data, array $dimensionAttributes): DimensionContentInterface;

/**
* @template T of DimensionContentInterface
*
* @param T $dimensionContent
*
* @return mixed[]
*/
public function normalize(DimensionContentInterface $dimensionContent): array;

/**
* @template T of DimensionContentInterface
*
* @param ContentRichEntityInterface<T> $sourceContentRichEntity
* @param mixed[] $sourceDimensionAttributes
* @param ContentRichEntityInterface<T> $targetContentRichEntity
* @param mixed[] $targetDimensionAttributes
*
* @return T
*/
public function copy(
ContentRichEntityInterface $sourceContentRichEntity,
Expand All @@ -46,7 +66,12 @@ public function copy(
): DimensionContentInterface;

/**
* @template T of DimensionContentInterface
*
* @param ContentRichEntityInterface<T> $contentRichEntity
* @param mixed[] $dimensionAttributes
*
* @return T
*/
public function applyTransition(
ContentRichEntityInterface $contentRichEntity,
Expand All @@ -55,12 +80,17 @@ public function applyTransition(
): DimensionContentInterface;

/**
* @template T of DimensionContentInterface
*
* @param ContentRichEntityInterface<T> $contentRichEntity
* @param mixed[] $dimensionAttributes
*
* @return T
*/
public function index(ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes): DimensionContentInterface;

/**
* @param mixed $id
* @param int|string $id
* @param mixed[] $dimensionAttributes
*/
public function deindex(string $resourceKey, $id, array $dimensionAttributes = []): void;
Expand Down
7 changes: 7 additions & 0 deletions Content/Application/ContentMerger/ContentMergerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,12 @@

interface ContentMergerInterface
{
/**
* @template T of DimensionContentInterface
*
* @param DimensionContentCollectionInterface<T> $dimensionContentCollection
*
* @return T
*/
public function merge(DimensionContentCollectionInterface $dimensionContentCollection): DimensionContentInterface;
}
4 changes: 2 additions & 2 deletions Content/Application/ContentMerger/Merger/ExcerptMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public function merge(object $targetObject, object $sourceObject): void
}

if ($excerptTags = $sourceObject->getExcerptTags()) {
if (!empty($excerptTags)) {
if (\count($excerptTags) > 0) { // @phpstan-ignore-line false positive for phpstan thinks it is a non-empty-array
$targetObject->setExcerptTags($excerptTags);
}
}

if ($excerptCategories = $sourceObject->getExcerptCategories()) {
if (!empty($excerptCategories)) {
if (\count($excerptCategories) > 0) { // @phpstan-ignore-line false positive for phpstan thinks it is a non-empty-array
$targetObject->setExcerptCategories($excerptCategories);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentMetadataInspector;

use Doctrine\ORM\EntityManagerInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;

class ContentMetadataInspector implements ContentMetadataInspectorInterface
Expand All @@ -28,10 +29,17 @@ public function __construct(EntityManagerInterface $entityManager)
$this->entityManager = $entityManager;
}

/**
* @template T of DimensionContentInterface
*
* @param class-string<ContentRichEntityInterface<T>> $contentRichEntityClass
*
* @return class-string<T>
*/
public function getDimensionContentClass(string $contentRichEntityClass): string
{
$classMetadata = $this->entityManager->getClassMetadata($contentRichEntityClass);
/** @var array{targetEntity: class-string<DimensionContentInterface>} $associationMapping */
/** @var array{targetEntity: class-string<T>} $associationMapping */
$associationMapping = $classMetadata->getAssociationMapping('dimensionContents');

return $associationMapping['targetEntity'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
interface ContentMetadataInspectorInterface
{
/**
* @param class-string<ContentRichEntityInterface> $contentRichEntityClass
* @template T of DimensionContentInterface
*
* @return class-string<DimensionContentInterface>
* @param class-string<ContentRichEntityInterface<T>> $contentRichEntityClass
*
* @return class-string<T>
*/
public function getDimensionContentClass(string $contentRichEntityClass): string;

/**
* @param class-string<ContentRichEntityInterface> $contentRichEntityClass
* @template T of DimensionContentInterface
*
* @param class-string<ContentRichEntityInterface<T>> $contentRichEntityClass
*/
public function getDimensionContentPropertyName(string $contentRichEntityClass): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function enhance(object $object, array $normalizedData): array
return $normalizedData;
}

$normalizedData = \array_merge($normalizedData['templateData'], $normalizedData);
$normalizedData = \array_merge($normalizedData['templateData'], $normalizedData); // @phpstan-ignore-line TODO check whats going on here
unset($normalizedData['templateData']);

$normalizedData['template'] = $normalizedData['templateKey'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
interface ContentPersisterInterface
{
/**
* @template T of DimensionContentInterface
*
* @param ContentRichEntityInterface<T> $contentRichEntity
* @param mixed[] $data
* @param mixed[] $dimensionAttributes
*
* @return T
*/
public function persist(ContentRichEntityInterface $contentRichEntity, array $data, array $dimensionAttributes): DimensionContentInterface;
}
Loading