diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3194d21298..16a068cc2c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10608,18 +10608,6 @@ parameters: count: 1 path: src/lib/FieldType/BinaryBase/Type.php - - - message: '#^Access to an undefined property Ibexa\\Core\\FieldType\\Value\:\:\$fileName\.$#' - identifier: property.notFound - count: 1 - path: src/lib/FieldType/BinaryBase/Type.php - - - - message: '#^Access to an undefined property Ibexa\\Core\\FieldType\\Value\:\:\$fileSize\.$#' - identifier: property.notFound - count: 1 - path: src/lib/FieldType/BinaryBase/Type.php - - message: '#^Method Ibexa\\Core\\FieldType\\BinaryBase\\Type\:\:checkValueStructure\(\) has no return type specified\.$#' identifier: missingType.return @@ -10674,6 +10662,12 @@ parameters: count: 1 path: src/lib/FieldType/BinaryBase/Type.php + - + message: '#^Property Ibexa\\Core\\FieldType\\BinaryBase\\Value\:\:\$fileSize \(int\|null\) does not accept int\<0, max\>\|false\.$#' + identifier: assign.propertyType + count: 1 + path: src/lib/FieldType/BinaryBase/Type.php + - message: '#^Method Ibexa\\Core\\FieldType\\BinaryBase\\Value\:\:__construct\(\) has parameter \$fileData with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -12750,6 +12744,18 @@ parameters: count: 1 path: src/lib/Helper/FieldsGroups/RepositoryConfigFieldsGroupsListFactory.php + - + message: '#^Access to an undefined property Ibexa\\Contracts\\Core\\Repository\\Values\\ValueObject\:\:\$alwaysAvailable\.$#' + identifier: property.notFound + count: 1 + path: src/lib/Helper/TranslationHelper.php + + - + message: '#^Access to an undefined property Ibexa\\Contracts\\Core\\Repository\\Values\\ValueObject\:\:\$mainLanguageCode\.$#' + identifier: property.notFound + count: 1 + path: src/lib/Helper/TranslationHelper.php + - message: '#^Method Ibexa\\Core\\Helper\\TranslationHelper\:\:__construct\(\) has parameter \$siteAccessesByLanguage with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -52584,12 +52590,6 @@ parameters: count: 1 path: tests/lib/FieldType/ImageAssetTest.php - - - message: '#^Access to an undefined property Ibexa\\Tests\\Core\\FieldType\\ImageTest\:\:\$mimeTypeDetectorMock\.$#' - identifier: property.notFound - count: 1 - path: tests/lib/FieldType/ImageTest.php - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\ImageTest\:\:getBlackListValidatorMock\(\) has no return type specified\.$#' identifier: missingType.return @@ -53700,12 +53700,6 @@ parameters: count: 1 path: tests/lib/FieldType/TimeTest.php - - - message: '#^Access to an undefined property Ibexa\\Tests\\Core\\FieldType\\Url\\Gateway\\DoctrineStorageTest\:\:\$storageGateway\.$#' - identifier: property.notFound - count: 1 - path: tests/lib/FieldType/Url/Gateway/DoctrineStorageTest.php - - message: '#^Method Ibexa\\Tests\\Core\\FieldType\\Url\\Gateway\\DoctrineStorageTest\:\:testGetIdUrlMap\(\) has no return type specified\.$#' identifier: missingType.return diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c8255a56e1..6a8bbef7fe 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -7,6 +7,8 @@ includes: parameters: level: 8 treatPhpDocTypesAsCertain: false + checkDynamicProperties: true + ignoreErrors: - message: "#^Cannot call method (fetchOne|fetchColumn|fetchAllAssociative|fetchAssociative|fetchAllKeyValue|fetchFirstColumn|rowCount)\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#" diff --git a/src/bundle/Core/Resources/config/templating.yml b/src/bundle/Core/Resources/config/templating.yml index ad7839456e..1b1f5bde0e 100644 --- a/src/bundle/Core/Resources/config/templating.yml +++ b/src/bundle/Core/Resources/config/templating.yml @@ -201,7 +201,7 @@ services: - { name: ibexa.view.render.strategy } Ibexa\Core\MVC\Symfony\Templating\Twig\Extension\ImageExtension: - class: Ibexa\Core\MVC\Symfony\Templating\Twig\Extension\ImageExtension + autoconfigure: true arguments: - '@ibexa.field_type.ezimage.variation_service' - '@Ibexa\Core\FieldType\ImageAsset\AssetMapper' diff --git a/src/lib/FieldType/Author/Type.php b/src/lib/FieldType/Author/Type.php index 61db3acff0..8ae81dbdf5 100644 --- a/src/lib/FieldType/Author/Type.php +++ b/src/lib/FieldType/Author/Type.php @@ -52,6 +52,9 @@ public function getFieldTypeIdentifier() return 'ezauthor'; } + /** + * @param \Ibexa\Core\FieldType\Author\Value $value + */ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, string $languageCode): string { return $value->authors[0]->name ?? ''; @@ -103,11 +106,11 @@ protected function checkValueStructure(BaseValue $value) } /** - * {@inheritdoc} + * @param \Ibexa\Core\FieldType\Author\Value $value */ protected function getSortInfo(BaseValue $value) { - if (empty($value->authors)) { + if (count($value->authors) === 0) { return false; } diff --git a/src/lib/FieldType/BinaryBase/Type.php b/src/lib/FieldType/BinaryBase/Type.php index fa9b750b16..f70092daca 100644 --- a/src/lib/FieldType/BinaryBase/Type.php +++ b/src/lib/FieldType/BinaryBase/Type.php @@ -148,7 +148,7 @@ protected function checkValueStructure(BaseValue $value) /** * Attempts to complete the data in $value. * - * @param \Ibexa\Core\FieldType\BinaryBase\Value|\Ibexa\Core\FieldType\Value $value + * @param \Ibexa\Core\FieldType\BinaryBase\Value $value */ protected function completeValue(BaseValue $value) { diff --git a/src/lib/FieldType/ImageAsset/Type.php b/src/lib/FieldType/ImageAsset/Type.php index ac77946f59..378ad5959f 100644 --- a/src/lib/FieldType/ImageAsset/Type.php +++ b/src/lib/FieldType/ImageAsset/Type.php @@ -102,7 +102,7 @@ public function getFieldTypeIdentifier(): string } /** - * @param \Ibexa\Core\FieldType\ImageAsset\Value|\Ibexa\Contracts\Core\FieldType\Value $value + * @param \Ibexa\Core\FieldType\ImageAsset\Value $value */ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, string $languageCode): string { diff --git a/src/lib/FieldType/Relation/Type.php b/src/lib/FieldType/Relation/Type.php index 90dc13f508..2cd27c8a1e 100644 --- a/src/lib/FieldType/Relation/Type.php +++ b/src/lib/FieldType/Relation/Type.php @@ -151,7 +151,7 @@ public function getFieldTypeIdentifier() } /** - * @param \Ibexa\Core\FieldType\Relation\Value|\Ibexa\Contracts\Core\FieldType\Value $value + * @param \Ibexa\Core\FieldType\Relation\Value $value */ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, string $languageCode): string { diff --git a/src/lib/FieldType/RelationList/Type.php b/src/lib/FieldType/RelationList/Type.php index abc34b59a1..7f0629a8d3 100644 --- a/src/lib/FieldType/RelationList/Type.php +++ b/src/lib/FieldType/RelationList/Type.php @@ -301,7 +301,7 @@ public function getFieldTypeIdentifier() } /** - * @param \Ibexa\Core\FieldType\RelationList\Value|\Ibexa\Contracts\Core\FieldType\Value $value + * @param \Ibexa\Core\FieldType\RelationList\Value $value */ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, string $languageCode): string { diff --git a/src/lib/FieldType/Selection/Type.php b/src/lib/FieldType/Selection/Type.php index cfb091bf2a..fd4a1825b5 100644 --- a/src/lib/FieldType/Selection/Type.php +++ b/src/lib/FieldType/Selection/Type.php @@ -126,7 +126,7 @@ public function getFieldTypeIdentifier() } /** - * @param \Ibexa\Core\FieldType\Selection\Value|\Ibexa\Contracts\Core\FieldType\Value $value + * @param \Ibexa\Core\FieldType\Selection\Value $value */ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, string $languageCode): string { diff --git a/src/lib/FieldType/Validator/ImageValidator.php b/src/lib/FieldType/Validator/ImageValidator.php index ae57f81f4a..1cc8dc39a9 100644 --- a/src/lib/FieldType/Validator/ImageValidator.php +++ b/src/lib/FieldType/Validator/ImageValidator.php @@ -22,7 +22,7 @@ public function validateConstraints($constraints, ?FieldDefinition $fieldDefinit } /** - * {@inheritdoc} + * @param \Ibexa\Core\FieldType\Image\Value $value */ public function validate(Value $value, ?FieldDefinition $fieldDefinition = null) { diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php index c77507c52c..0a8b95957f 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php @@ -13,11 +13,15 @@ use Ibexa\Core\FieldType\ImageAsset\AssetMapper; use Ibexa\Core\MVC\Exception\SourceImageNotFoundException; use InvalidArgumentException; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; -class ImageExtension extends AbstractExtension +class ImageExtension extends AbstractExtension implements LoggerAwareInterface { + use LoggerAwareTrait; + use DeprecationOptionsTrait; /** @var \Ibexa\Contracts\Core\Variation\VariationHandler */ diff --git a/tests/lib/FieldType/ImageTest.php b/tests/lib/FieldType/ImageTest.php index bcf4b96c2e..bc21d149e7 100644 --- a/tests/lib/FieldType/ImageTest.php +++ b/tests/lib/FieldType/ImageTest.php @@ -37,21 +37,17 @@ class ImageTest extends FieldTypeTest 'pgif', ]; + /** @var \Ibexa\Contracts\Core\IO\MimeTypeDetector&\PHPUnit\Framework\MockObject\MockObject */ + private MimeTypeDetector $mimeTypeDetectorMock; + public function getImageInputPath() { return __DIR__ . '/../_fixtures/squirrel-developers.jpg'; } - /** - * @return \Ibexa\Contracts\Core\IO\MimeTypeDetector - */ - protected function getMimeTypeDetectorMock() + protected function getMimeTypeDetectorMock(): MimeTypeDetector { - if (!isset($this->mimeTypeDetectorMock)) { - $this->mimeTypeDetectorMock = $this->createMock(MimeTypeDetector::class); - } - - return $this->mimeTypeDetectorMock; + return $this->mimeTypeDetectorMock ??= $this->createMock(MimeTypeDetector::class); } /** diff --git a/tests/lib/FieldType/Url/Gateway/DoctrineStorageTest.php b/tests/lib/FieldType/Url/Gateway/DoctrineStorageTest.php index 508b892a58..37ba95ad3e 100644 --- a/tests/lib/FieldType/Url/Gateway/DoctrineStorageTest.php +++ b/tests/lib/FieldType/Url/Gateway/DoctrineStorageTest.php @@ -15,6 +15,8 @@ */ class DoctrineStorageTest extends TestCase { + private DoctrineStorage $storageGateway; + /** * @covers \Ibexa\Core\FieldType\Url\UrlStorage\Gateway\DoctrineStorage::getIdUrlMap */ @@ -196,11 +198,7 @@ public function testUnlinkUrl() protected function getStorageGateway(): Gateway { - if (!isset($this->storageGateway)) { - $this->storageGateway = new DoctrineStorage($this->getDatabaseConnection()); - } - - return $this->storageGateway; + return $this->storageGateway ??= new DoctrineStorage($this->getDatabaseConnection()); } } diff --git a/tests/lib/Repository/Values/Content/LanguageTest.php b/tests/lib/Repository/Values/Content/LanguageTest.php index cc023cc16e..8531d9566b 100644 --- a/tests/lib/Repository/Values/Content/LanguageTest.php +++ b/tests/lib/Repository/Values/Content/LanguageTest.php @@ -46,6 +46,7 @@ public function testMissingProperty() $this->expectExceptionMessage('Property \'notDefined\' not found on class'); $language = new Language(); + /** @phpstan-ignore-next-line property.notFound */ $value = $language->notDefined; self::fail('Succeeded getting non existing property'); } diff --git a/tests/lib/Repository/Values/Content/LocationTest.php b/tests/lib/Repository/Values/Content/LocationTest.php index 082d8a796b..a3e4caa3c0 100644 --- a/tests/lib/Repository/Values/Content/LocationTest.php +++ b/tests/lib/Repository/Values/Content/LocationTest.php @@ -121,6 +121,7 @@ public function testMissingProperty(): void $this->expectException(PropertyNotFoundException::class); $location = new Location(); + /** @phpstan-ignore-next-line property.notFound */ $value = $location->notDefined; self::fail('Succeeded getting non existing property'); } diff --git a/tests/lib/Repository/Values/Content/SectionTest.php b/tests/lib/Repository/Values/Content/SectionTest.php index f4cd626170..0d55505f95 100644 --- a/tests/lib/Repository/Values/Content/SectionTest.php +++ b/tests/lib/Repository/Values/Content/SectionTest.php @@ -45,6 +45,7 @@ public function testMissingProperty() $this->expectException(PropertyNotFoundException::class); $section = new Section(); + /** @phpstan-ignore-next-line property.notFound */ $value = $section->notDefined; self::fail('Succeeded getting non existing property'); } diff --git a/tests/lib/Repository/Values/Content/TrashItemTest.php b/tests/lib/Repository/Values/Content/TrashItemTest.php index d9b6013d7d..a65c82fed5 100644 --- a/tests/lib/Repository/Values/Content/TrashItemTest.php +++ b/tests/lib/Repository/Values/Content/TrashItemTest.php @@ -54,6 +54,7 @@ public function testMissingProperty() $this->expectException(PropertyNotFoundException::class); $trashItem = new TrashItem(); + /** @phpstan-ignore-next-line property.notFound */ $value = $trashItem->notDefined; self::fail('Succeeded getting non existing property'); } diff --git a/tests/lib/Repository/Values/ObjectState/ObjectStateGroupTest.php b/tests/lib/Repository/Values/ObjectState/ObjectStateGroupTest.php index dbbc8f2952..b6c56dd071 100644 --- a/tests/lib/Repository/Values/ObjectState/ObjectStateGroupTest.php +++ b/tests/lib/Repository/Values/ObjectState/ObjectStateGroupTest.php @@ -81,6 +81,7 @@ public function testMissingProperty() $this->expectException(PropertyNotFoundException::class); $objectStateGroup = new ObjectStateGroup(); + /** @phpstan-ignore-next-line property.notFound */ $value = $objectStateGroup->notDefined; $this->fail('Succeeded getting non existing property'); } diff --git a/tests/lib/Repository/Values/ObjectState/ObjectStateTest.php b/tests/lib/Repository/Values/ObjectState/ObjectStateTest.php index 41255bfb60..8fc060293a 100644 --- a/tests/lib/Repository/Values/ObjectState/ObjectStateTest.php +++ b/tests/lib/Repository/Values/ObjectState/ObjectStateTest.php @@ -83,6 +83,7 @@ public function testMissingProperty() $this->expectException(PropertyNotFoundException::class); $objectState = new ObjectState(); + /** @phpstan-ignore-next-line property.notFound */ $value = $objectState->notDefined; $this->fail('Succeeded getting non existing property'); } diff --git a/tests/lib/Repository/Values/User/PolicyTest.php b/tests/lib/Repository/Values/User/PolicyTest.php index 4b82889e59..f1fa34179b 100644 --- a/tests/lib/Repository/Values/User/PolicyTest.php +++ b/tests/lib/Repository/Values/User/PolicyTest.php @@ -45,6 +45,7 @@ public function testMissingProperty() $this->expectException(PropertyNotFoundException::class); $policy = new Policy(); + /** @phpstan-ignore-next-line property.notFound */ $value = $policy->notDefined; self::fail('Succeeded getting non existing property'); } diff --git a/tests/lib/Repository/Values/User/RoleTest.php b/tests/lib/Repository/Values/User/RoleTest.php index e506323d13..6f571a2ef0 100644 --- a/tests/lib/Repository/Values/User/RoleTest.php +++ b/tests/lib/Repository/Values/User/RoleTest.php @@ -44,6 +44,7 @@ public function testMissingProperty() $this->expectException(PropertyNotFoundException::class); $role = new Role(); + /** @phpstan-ignore-next-line property.notFound */ $value = $role->notDefined; self::fail('Succeeded getting non existing property'); } diff --git a/tests/lib/Repository/Values/User/UserGroupTest.php b/tests/lib/Repository/Values/User/UserGroupTest.php index 755dac342f..d36558f9fc 100644 --- a/tests/lib/Repository/Values/User/UserGroupTest.php +++ b/tests/lib/Repository/Values/User/UserGroupTest.php @@ -64,6 +64,7 @@ public function testMissingProperty() $this->expectException(PropertyNotFoundException::class); $userGroup = new UserGroup(); + /** @phpstan-ignore-next-line property.notFound */ $value = $userGroup->notDefined; self::fail('Succeeded getting non existing property'); } diff --git a/tests/lib/Repository/Values/User/UserTest.php b/tests/lib/Repository/Values/User/UserTest.php index 24b2cf13f3..4fa67bf959 100644 --- a/tests/lib/Repository/Values/User/UserTest.php +++ b/tests/lib/Repository/Values/User/UserTest.php @@ -71,6 +71,7 @@ public function testMissingProperty() $this->expectException(PropertyNotFoundException::class); $user = new User(); + /** @phpstan-ignore-next-line property.notFound */ $value = $user->notDefined; self::fail('Succeeded getting non existing property'); }