From beccbba73965d412c785c90705fb26ff7708dc1b Mon Sep 17 00:00:00 2001 From: Raymond Schouten Date: Wed, 11 Feb 2026 10:15:42 +0100 Subject: [PATCH 1/2] #274: Disabled new PHP CS Fixer rule --- symfony-addon-constraints/.php-cs-fixer.dist.php | 1 + symfony-addon-form-types/.php-cs-fixer.dist.php | 1 + symfony-addon-transformers/.php-cs-fixer.dist.php | 1 + 3 files changed, 3 insertions(+) diff --git a/symfony-addon-constraints/.php-cs-fixer.dist.php b/symfony-addon-constraints/.php-cs-fixer.dist.php index 6a598a6..0f99cf8 100644 --- a/symfony-addon-constraints/.php-cs-fixer.dist.php +++ b/symfony-addon-constraints/.php-cs-fixer.dist.php @@ -19,6 +19,7 @@ 'global_namespace_import' => ['import_classes' => false], 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], // overrules @PhpCsFixer 'no_superfluous_elseif' => false, // overrules @PhpCsFixer + 'php_unit_data_provider_method_order' => false, // overrules @PhpCsFixer 'phpdoc_align' => ['tags' => ['method', 'param', 'property', 'return', 'throws', 'type', 'var'], 'align' => 'left'], // overrules @Symfony 'yoda_style' => false, // overrules @Symfony ]) diff --git a/symfony-addon-form-types/.php-cs-fixer.dist.php b/symfony-addon-form-types/.php-cs-fixer.dist.php index 6a598a6..0f99cf8 100644 --- a/symfony-addon-form-types/.php-cs-fixer.dist.php +++ b/symfony-addon-form-types/.php-cs-fixer.dist.php @@ -19,6 +19,7 @@ 'global_namespace_import' => ['import_classes' => false], 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], // overrules @PhpCsFixer 'no_superfluous_elseif' => false, // overrules @PhpCsFixer + 'php_unit_data_provider_method_order' => false, // overrules @PhpCsFixer 'phpdoc_align' => ['tags' => ['method', 'param', 'property', 'return', 'throws', 'type', 'var'], 'align' => 'left'], // overrules @Symfony 'yoda_style' => false, // overrules @Symfony ]) diff --git a/symfony-addon-transformers/.php-cs-fixer.dist.php b/symfony-addon-transformers/.php-cs-fixer.dist.php index 6a598a6..0f99cf8 100644 --- a/symfony-addon-transformers/.php-cs-fixer.dist.php +++ b/symfony-addon-transformers/.php-cs-fixer.dist.php @@ -19,6 +19,7 @@ 'global_namespace_import' => ['import_classes' => false], 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], // overrules @PhpCsFixer 'no_superfluous_elseif' => false, // overrules @PhpCsFixer + 'php_unit_data_provider_method_order' => false, // overrules @PhpCsFixer 'phpdoc_align' => ['tags' => ['method', 'param', 'property', 'return', 'throws', 'type', 'var'], 'align' => 'left'], // overrules @Symfony 'yoda_style' => false, // overrules @Symfony ]) From 19b96a6e11b210c5e10b291908673f0d203e397e Mon Sep 17 00:00:00 2001 From: Raymond Schouten Date: Wed, 11 Feb 2026 11:45:51 +0100 Subject: [PATCH 2/2] #274: Applied code quality tools --- composer.json | 14 ++--- phpstan.dist.neon | 2 + rector.php | 15 +++--- symfony-addon-constraints/composer.json | 12 ++--- symfony-addon-constraints/phpstan.dist.neon | 2 + symfony-addon-constraints/rector.php | 15 +++--- .../src/BsnValidator.php | 2 +- .../tests/BsnValidatorTest.php | 42 +++++++-------- .../tests/CollectionTest.php | 9 ++-- .../tests/CollectionValidatorTest.php | 34 ++++++------ .../tests/JsonValidatorTest.php | 48 ++++++++--------- symfony-addon-form-types/composer.json | 14 ++--- symfony-addon-form-types/phpstan.dist.neon | 2 + symfony-addon-form-types/rector.php | 15 +++--- symfony-addon-form-types/src/BirthdayType.php | 2 + symfony-addon-form-types/src/BooleanType.php | 4 ++ symfony-addon-form-types/src/EntityType.php | 4 ++ .../src/UnstructuredType.php | 2 + .../tests/BirthdayTypeTest.php | 2 +- .../tests/BooleanToYesNoSubscriberTest.php | 14 +++-- .../tests/BooleanTypeTest.php | 30 +++++------ .../tests/EntityTypeTest.php | 12 ++--- .../tests/JsonSchemaSubscriberTest.php | 2 +- .../tests/UnstructuredTypeTest.php | 2 +- symfony-addon-transformers/composer.json | 14 ++--- symfony-addon-transformers/phpstan.dist.neon | 2 + symfony-addon-transformers/rector.php | 15 +++--- .../src/BooleanToValueTransformer.php | 2 +- .../src/EntityToIdentifierTransformer.php | 3 +- .../tests/BooleanToValueTransformerTest.php | 54 +++++++++---------- .../EntityToIdentifierTransformerTest.php | 50 ++++++++--------- 31 files changed, 214 insertions(+), 226 deletions(-) diff --git a/composer.json b/composer.json index 5d22803..280a748 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,15 @@ }, "require-dev": { "doctrine/orm": "^2.7", - "friendsofphp/php-cs-fixer": "^3.58", + "friendsofphp/php-cs-fixer": "^3.93", "maglnet/composer-require-checker": "^4.17", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.11", - "phpstan/phpstan-doctrine": "^1.4", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/phpstan-symfony": "^1.4", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-doctrine": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-symfony": "^2.0", "phpunit/phpunit": "^10.5", - "rector/rector": "^1.1" + "rector/rector": "^2.3" }, "suggest": { "doctrine/orm": "Required for EntityToIdentifierTransformer and EntityType" diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 3c6ca3f..830fe57 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -8,3 +8,5 @@ parameters: - 'symfony-addon-form-types/tests' - 'symfony-addon-transformers/src' - 'symfony-addon-transformers/tests' + + treatPhpDocTypesAsCertain: false diff --git a/rector.php b/rector.php index 07e379a..b4c9141 100644 --- a/rector.php +++ b/rector.php @@ -3,7 +3,6 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\Set\ValueObject\LevelSetList; return RectorConfig::configure() ->withPaths([ @@ -14,9 +13,11 @@ __DIR__ . '/symfony-addon-transformers/src', __DIR__ . '/symfony-addon-transformers/tests', ]) - ->withSets([ - LevelSetList::UP_TO_PHP_82, - ]) - ->withImportNames( - importShortClasses: false, - ); + ->withPhpSets() + ->withAttributesSets() + ->withPreparedSets(phpunitCodeQuality: true, doctrineCodeQuality: true, symfonyCodeQuality: true, symfonyConfigs: true) + ->withComposerBased(doctrine: true, phpunit: true, symfony: true) + ->withImportNames(importShortClasses: false, removeUnusedImports: true) + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/symfony-addon-constraints/composer.json b/symfony-addon-constraints/composer.json index 46bc3aa..59ca6c6 100644 --- a/symfony-addon-constraints/composer.json +++ b/symfony-addon-constraints/composer.json @@ -14,14 +14,14 @@ "symfony/validator": "7.3.*" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.58", + "friendsofphp/php-cs-fixer": "^3.93", "maglnet/composer-require-checker": "^4.17", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.11", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/phpstan-symfony": "^1.4", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-symfony": "^2.0", "phpunit/phpunit": "^10.5", - "rector/rector": "^1.1" + "rector/rector": "^2.3" }, "suggest": { "darkwebdesign/symfony-addon-pack": "All Symfony add-ons bundled together" diff --git a/symfony-addon-constraints/phpstan.dist.neon b/symfony-addon-constraints/phpstan.dist.neon index d58d3b6..59d1334 100644 --- a/symfony-addon-constraints/phpstan.dist.neon +++ b/symfony-addon-constraints/phpstan.dist.neon @@ -4,3 +4,5 @@ parameters: paths: - 'src' - 'tests' + + treatPhpDocTypesAsCertain: false diff --git a/symfony-addon-constraints/rector.php b/symfony-addon-constraints/rector.php index da41b57..5300568 100644 --- a/symfony-addon-constraints/rector.php +++ b/symfony-addon-constraints/rector.php @@ -3,16 +3,17 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\Set\ValueObject\LevelSetList; return RectorConfig::configure() ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', ]) - ->withSets([ - LevelSetList::UP_TO_PHP_82, - ]) - ->withImportNames( - importShortClasses: false, - ); + ->withPhpSets() + ->withAttributesSets() + ->withPreparedSets(phpunitCodeQuality: true, symfonyCodeQuality: true, symfonyConfigs: true) + ->withComposerBased(phpunit: true, symfony: true) + ->withImportNames(importShortClasses: false, removeUnusedImports: true) + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/symfony-addon-constraints/src/BsnValidator.php b/symfony-addon-constraints/src/BsnValidator.php index 5a97e65..77051c0 100644 --- a/symfony-addon-constraints/src/BsnValidator.php +++ b/symfony-addon-constraints/src/BsnValidator.php @@ -66,7 +66,7 @@ public function validate(mixed $value, Constraint $constraint): void $value = (string) $value; if ('000000000' !== $value && preg_match('/^\d{9}$/', $value)) { - [$a, $b, $c, $d, $e, $f, $g, $h, $i] = array_map('intval', str_split($value)); + [$a, $b, $c, $d, $e, $f, $g, $h, $i] = array_map(intval(...), str_split($value)); $sum = (9 * $a) + (8 * $b) + (7 * $c) + (6 * $d) + (5 * $e) + (4 * $f) + (3 * $g) + (2 * $h) + (-1 * $i); diff --git a/symfony-addon-constraints/tests/BsnValidatorTest.php b/symfony-addon-constraints/tests/BsnValidatorTest.php index 2842c8f..ac503fc 100644 --- a/symfony-addon-constraints/tests/BsnValidatorTest.php +++ b/symfony-addon-constraints/tests/BsnValidatorTest.php @@ -38,7 +38,7 @@ * @internal */ #[CoversClass(BsnValidator::class)] -class BsnValidatorTest extends ConstraintValidatorTestCase +final class BsnValidatorTest extends ConstraintValidatorTestCase { protected function createValidator(): BsnValidator { @@ -99,40 +99,34 @@ public function testValidateViolation(string|\Stringable $value): void } /** - * @return array + * @return \Iterator */ - public static function providerValidBsn(): array + public static function providerValidBsn(): \Iterator { - return [ - 'valid1' => ['111222333'], - 'valid2' => ['123456782'], - 'objectToString' => [new ToStringObject('270590791')], - ]; + yield 'valid1' => ['111222333']; + yield 'valid2' => ['123456782']; + yield 'objectToString' => [new ToStringObject('270590791')]; } /** - * @return array + * @return \Iterator */ - public static function providerNoScalar(): array + public static function providerNoScalar(): \Iterator { - return [ - 'array' => [['foo', 'bar']], - 'object' => [new \stdClass()], - 'resource' => [tmpfile()], - 'callable' => [function () {}], - ]; + yield 'array' => [['foo', 'bar']]; + yield 'object' => [new \stdClass()]; + yield 'resource' => [tmpfile()]; + yield 'callable' => [function (): void {}]; } /** - * @return array + * @return \Iterator */ - public static function providerInvalidBsn(): array + public static function providerInvalidBsn(): \Iterator { - return [ - 'zeros' => ['000000000'], - 'invalid1' => ['999999999'], - 'invalid2' => ['876543242'], - 'toStringObject' => [new ToStringObject('597944111')], - ]; + yield 'zeros' => ['000000000']; + yield 'invalid1' => ['999999999']; + yield 'invalid2' => ['876543242']; + yield 'toStringObject' => [new ToStringObject('597944111')]; } } diff --git a/symfony-addon-constraints/tests/CollectionTest.php b/symfony-addon-constraints/tests/CollectionTest.php index 9435aa3..10f979d 100644 --- a/symfony-addon-constraints/tests/CollectionTest.php +++ b/symfony-addon-constraints/tests/CollectionTest.php @@ -25,6 +25,7 @@ use DarkWebDesign\SymfonyAddonConstraints\Collection; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; @@ -34,8 +35,9 @@ * @internal */ #[CoversClass(Collection::class)] -class CollectionTest extends TestCase +final class CollectionTest extends TestCase { + #[DoesNotPerformAssertions] public function testConstruct(): void { new Collection([ @@ -43,17 +45,14 @@ public function testConstruct(): void new Assert\NotBlank(), ], ]); - - $this->assertTrue(true); } + #[DoesNotPerformAssertions] public function testConstructDefaultOption(): void { new Collection([ new Assert\NotBlank(), ]); - - $this->assertTrue(true); } public function testConstructMissingRequiredConstraintsOption(): void diff --git a/symfony-addon-constraints/tests/CollectionValidatorTest.php b/symfony-addon-constraints/tests/CollectionValidatorTest.php index 1ec073c..d3c2947 100644 --- a/symfony-addon-constraints/tests/CollectionValidatorTest.php +++ b/symfony-addon-constraints/tests/CollectionValidatorTest.php @@ -40,7 +40,7 @@ */ #[CoversClass(CollectionValidator::class)] #[UsesClass(Collection::class)] -class CollectionValidatorTest extends ConstraintValidatorTestCase +final class CollectionValidatorTest extends ConstraintValidatorTestCase { protected function createValidator(): CollectionValidator { @@ -102,30 +102,26 @@ public function testValidateNoArray(mixed $value): void } /** - * @return array + * @return \Iterator}> */ - public static function providerValidCollection(): array + public static function providerValidCollection(): \Iterator { - return [ - 'empty' => [[]], - 'array' => [['my.email@address.com']], - 'traversableObject' => [new TraversableObject(['my.email@address.com'])], - ]; + yield 'empty' => [[]]; + yield 'array' => [['my.email@address.com']]; + yield 'traversableObject' => [new TraversableObject(['my.email@address.com'])]; } /** - * @return array + * @return \Iterator */ - public static function providerNoArray(): array + public static function providerNoArray(): \Iterator { - return [ - 'bool' => [true], - 'int' => [1], - 'float' => [1.2], - 'string' => ['foo'], - 'object' => [new \stdClass()], - 'resource' => [tmpfile()], - 'callable' => [function () {}], - ]; + yield 'bool' => [true]; + yield 'int' => [1]; + yield 'float' => [1.2]; + yield 'string' => ['foo']; + yield 'object' => [new \stdClass()]; + yield 'resource' => [tmpfile()]; + yield 'callable' => [function (): void {}]; } } diff --git a/symfony-addon-constraints/tests/JsonValidatorTest.php b/symfony-addon-constraints/tests/JsonValidatorTest.php index 2524ae8..6f6bae0 100644 --- a/symfony-addon-constraints/tests/JsonValidatorTest.php +++ b/symfony-addon-constraints/tests/JsonValidatorTest.php @@ -38,7 +38,7 @@ * @internal */ #[CoversClass(JsonValidator::class)] -class JsonValidatorTest extends ConstraintValidatorTestCase +final class JsonValidatorTest extends ConstraintValidatorTestCase { protected function createValidator(): JsonValidator { @@ -99,43 +99,37 @@ public function testValidateViolation(string $value): void } /** - * @return array + * @return \Iterator */ - public static function providerValidJson(): array + public static function providerValidJson(): \Iterator { - return [ - 'bool' => [true], - 'int' => [123], - 'float' => [10.99], - 'stringInt' => ['123'], - 'stringArray' => ['[1, 2, 3]'], - 'stringObject' => ['{"a": 1, "b": 2}'], - 'objectToString' => [new ToStringObject('123')], - ]; + yield 'bool' => [true]; + yield 'int' => [123]; + yield 'float' => [10.99]; + yield 'stringInt' => ['123']; + yield 'stringArray' => ['[1, 2, 3]']; + yield 'stringObject' => ['{"a": 1, "b": 2}']; + yield 'objectToString' => [new ToStringObject('123')]; } /** - * @return array + * @return \Iterator */ - public static function providerNoScalar(): array + public static function providerNoScalar(): \Iterator { - return [ - 'array' => [['foo', 'bar']], - 'object' => [new \stdClass()], - 'resource' => [tmpfile()], - 'callable' => [function () {}], - ]; + yield 'array' => [['foo', 'bar']]; + yield 'object' => [new \stdClass()]; + yield 'resource' => [tmpfile()]; + yield 'callable' => [function (): void {}]; } /** - * @return array + * @return \Iterator */ - public static function providerInvalidJson(): array + public static function providerInvalidJson(): \Iterator { - return [ - 'string' => ['json'], - 'stringArray' => ['[1, 2, 3'], - 'stringObject' => ['{"a": 1, "b": 2'], - ]; + yield 'string' => ['json']; + yield 'stringArray' => ['[1, 2, 3']; + yield 'stringObject' => ['{"a": 1, "b": 2']; } } diff --git a/symfony-addon-form-types/composer.json b/symfony-addon-form-types/composer.json index e8f64cf..636fda0 100644 --- a/symfony-addon-form-types/composer.json +++ b/symfony-addon-form-types/composer.json @@ -17,15 +17,15 @@ "require-dev": { "darkwebdesign/symfony-addon-transformers": "7.3.*", "doctrine/orm": "^2.7", - "friendsofphp/php-cs-fixer": "^3.58", + "friendsofphp/php-cs-fixer": "^3.93", "maglnet/composer-require-checker": "^4.17", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.11", - "phpstan/phpstan-doctrine": "^1.4", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/phpstan-symfony": "^1.4", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-doctrine": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-symfony": "^2.0", "phpunit/phpunit": "^10.5", - "rector/rector": "^1.1" + "rector/rector": "^2.3" }, "suggest": { "darkwebdesign/symfony-addon-pack": "All Symfony add-ons bundled together", diff --git a/symfony-addon-form-types/phpstan.dist.neon b/symfony-addon-form-types/phpstan.dist.neon index d58d3b6..59d1334 100644 --- a/symfony-addon-form-types/phpstan.dist.neon +++ b/symfony-addon-form-types/phpstan.dist.neon @@ -4,3 +4,5 @@ parameters: paths: - 'src' - 'tests' + + treatPhpDocTypesAsCertain: false diff --git a/symfony-addon-form-types/rector.php b/symfony-addon-form-types/rector.php index da41b57..aa82129 100644 --- a/symfony-addon-form-types/rector.php +++ b/symfony-addon-form-types/rector.php @@ -3,16 +3,17 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\Set\ValueObject\LevelSetList; return RectorConfig::configure() ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', ]) - ->withSets([ - LevelSetList::UP_TO_PHP_82, - ]) - ->withImportNames( - importShortClasses: false, - ); + ->withPhpSets() + ->withAttributesSets() + ->withPreparedSets(phpunitCodeQuality: true, doctrineCodeQuality: true, symfonyCodeQuality: true, symfonyConfigs: true) + ->withComposerBased(doctrine: true, phpunit: true, symfony: true) + ->withImportNames(importShortClasses: false, removeUnusedImports: true) + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/symfony-addon-form-types/src/BirthdayType.php b/symfony-addon-form-types/src/BirthdayType.php index 4526cb2..e08e744 100644 --- a/symfony-addon-form-types/src/BirthdayType.php +++ b/symfony-addon-form-types/src/BirthdayType.php @@ -31,6 +31,8 @@ * @author Raymond Schouten * * @since 2.3 + * + * @extends AbstractType */ class BirthdayType extends AbstractType { diff --git a/symfony-addon-form-types/src/BooleanType.php b/symfony-addon-form-types/src/BooleanType.php index b261897..8fa056a 100644 --- a/symfony-addon-form-types/src/BooleanType.php +++ b/symfony-addon-form-types/src/BooleanType.php @@ -34,6 +34,10 @@ * @author Raymond Schouten * * @since 2.3 + * + * @template TData as array + * + * @extends AbstractType */ class BooleanType extends AbstractType { diff --git a/symfony-addon-form-types/src/EntityType.php b/symfony-addon-form-types/src/EntityType.php index f433595..6d953d7 100644 --- a/symfony-addon-form-types/src/EntityType.php +++ b/symfony-addon-form-types/src/EntityType.php @@ -42,6 +42,10 @@ * @author Raymond Schouten * * @since 2.3 + * + * @template TData as array + * + * @extends AbstractType */ class EntityType extends AbstractType { diff --git a/symfony-addon-form-types/src/UnstructuredType.php b/symfony-addon-form-types/src/UnstructuredType.php index 76f3fea..eea3914 100644 --- a/symfony-addon-form-types/src/UnstructuredType.php +++ b/symfony-addon-form-types/src/UnstructuredType.php @@ -30,6 +30,8 @@ * @author Raymond Schouten * * @since 3.4 + * + * @extends AbstractType */ class UnstructuredType extends AbstractType { diff --git a/symfony-addon-form-types/tests/BirthdayTypeTest.php b/symfony-addon-form-types/tests/BirthdayTypeTest.php index c2768d5..0e02fb4 100644 --- a/symfony-addon-form-types/tests/BirthdayTypeTest.php +++ b/symfony-addon-form-types/tests/BirthdayTypeTest.php @@ -31,7 +31,7 @@ * @internal */ #[CoversClass(BirthdayType::class)] -class BirthdayTypeTest extends TypeTestCase +final class BirthdayTypeTest extends TypeTestCase { public function test(): void { diff --git a/symfony-addon-form-types/tests/BooleanToYesNoSubscriberTest.php b/symfony-addon-form-types/tests/BooleanToYesNoSubscriberTest.php index 375f608..f98d880 100644 --- a/symfony-addon-form-types/tests/BooleanToYesNoSubscriberTest.php +++ b/symfony-addon-form-types/tests/BooleanToYesNoSubscriberTest.php @@ -37,7 +37,7 @@ #[CoversClass(BooleanToYesNoSubscriber::class)] #[UsesClass(BooleanType::class)] #[UsesClass(BooleanToValueTransformer::class)] -class BooleanToYesNoSubscriberTest extends TypeTestCase +final class BooleanToYesNoSubscriberTest extends TypeTestCase { #[DataProvider('provider')] public function test(?bool $value): void @@ -82,14 +82,12 @@ public function testDataNotArray(): void } /** - * @return array + * @return \Iterator */ - public static function provider(): array + public static function provider(): \Iterator { - return [ - 'true' => [true], - 'false' => [false], - 'null' => [null], - ]; + yield 'true' => [true]; + yield 'false' => [false]; + yield 'null' => [null]; } } diff --git a/symfony-addon-form-types/tests/BooleanTypeTest.php b/symfony-addon-form-types/tests/BooleanTypeTest.php index 16eadbe..8ceb783 100644 --- a/symfony-addon-form-types/tests/BooleanTypeTest.php +++ b/symfony-addon-form-types/tests/BooleanTypeTest.php @@ -35,7 +35,7 @@ */ #[CoversClass(BooleanType::class)] #[UsesClass(BooleanToValueTransformer::class)] -class BooleanTypeTest extends TypeTestCase +final class BooleanTypeTest extends TypeTestCase { #[DataProvider('providerValueTrueFalse')] public function test(mixed $valueTrue, mixed $valueFalse): void @@ -103,28 +103,24 @@ public function testHumanize(): void } /** - * @return array + * @return \Iterator */ - public static function providerValueTrueFalse(): array + public static function providerValueTrueFalse(): \Iterator { - return [ - 'true/false' => ['true', 'false'], - 'yes/no' => ['yes', 'no'], - 'on/off' => ['on', 'off'], - '1/0' => ['1', '0'], - '1/2' => [1, 2], - '1.3/2.7' => [1.3, 2.7], - ]; + yield 'true/false' => ['true', 'false']; + yield 'yes/no' => ['yes', 'no']; + yield 'on/off' => ['on', 'off']; + yield '1/0' => ['1', '0']; + yield '1/2' => [1, 2]; + yield '1.3/2.7' => [1.3, 2.7]; } /** - * @return array + * @return \Iterator */ - public static function providerWidget(): array + public static function providerWidget(): \Iterator { - return [ - 'choice' => ['choice', false], - 'radio' => ['radio', true], - ]; + yield 'choice' => ['choice', false]; + yield 'radio' => ['radio', true]; } } diff --git a/symfony-addon-form-types/tests/EntityTypeTest.php b/symfony-addon-form-types/tests/EntityTypeTest.php index 1c023f8..4e967e1 100644 --- a/symfony-addon-form-types/tests/EntityTypeTest.php +++ b/symfony-addon-form-types/tests/EntityTypeTest.php @@ -44,7 +44,7 @@ */ #[CoversClass(EntityType::class)] #[UsesClass(EntityToIdentifierTransformer::class)] -class EntityTypeTest extends TypeTestCase +final class EntityTypeTest extends TypeTestCase { private City $entity; /** @var class-string */ @@ -56,8 +56,6 @@ class EntityTypeTest extends TypeTestCase private ObjectManager $entityManager; /** @var ObjectRepository&MockObject */ private ObjectRepository $repository; - /** @var ClassMetadata&MockObject */ - private ClassMetadata $metadata; protected function setUp(): void { @@ -70,13 +68,13 @@ protected function setUp(): void $this->registry = $this->createMock(ManagerRegistry::class); $this->entityManager = $this->createMock(ObjectManager::class); $this->repository = $this->createMock(ObjectRepository::class); - $this->metadata = $this->createMock(ClassMetadata::class); + $metadata = $this->createMock(ClassMetadata::class); $this->entityManager->method('getRepository')->willReturn($this->repository); - $this->entityManager->method('getClassMetadata')->willReturn($this->metadata); + $this->entityManager->method('getClassMetadata')->willReturn($metadata); - $this->metadata->method('getName')->willReturn($this->className); - $this->metadata->method('getIdentifierValues')->willReturn(['id' => $this->identifier]); + $metadata->method('getName')->willReturn($this->className); + $metadata->method('getIdentifierValues')->willReturn(['id' => $this->identifier]); parent::setUp(); } diff --git a/symfony-addon-form-types/tests/JsonSchemaSubscriberTest.php b/symfony-addon-form-types/tests/JsonSchemaSubscriberTest.php index e7682a3..2d49725 100644 --- a/symfony-addon-form-types/tests/JsonSchemaSubscriberTest.php +++ b/symfony-addon-form-types/tests/JsonSchemaSubscriberTest.php @@ -32,7 +32,7 @@ * @internal */ #[CoversClass(JsonSchemaSubscriber::class)] -class JsonSchemaSubscriberTest extends TypeTestCase +final class JsonSchemaSubscriberTest extends TypeTestCase { public function test(): void { diff --git a/symfony-addon-form-types/tests/UnstructuredTypeTest.php b/symfony-addon-form-types/tests/UnstructuredTypeTest.php index 705790d..f3b37f7 100644 --- a/symfony-addon-form-types/tests/UnstructuredTypeTest.php +++ b/symfony-addon-form-types/tests/UnstructuredTypeTest.php @@ -31,7 +31,7 @@ * @internal */ #[CoversClass(UnstructuredType::class)] -class UnstructuredTypeTest extends TypeTestCase +final class UnstructuredTypeTest extends TypeTestCase { public function testArray(): void { diff --git a/symfony-addon-transformers/composer.json b/symfony-addon-transformers/composer.json index 50029c3..c828ae3 100644 --- a/symfony-addon-transformers/composer.json +++ b/symfony-addon-transformers/composer.json @@ -14,15 +14,15 @@ }, "require-dev": { "doctrine/orm": "^2.7", - "friendsofphp/php-cs-fixer": "^3.58", + "friendsofphp/php-cs-fixer": "^3.93", "maglnet/composer-require-checker": "^4.17", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.11", - "phpstan/phpstan-doctrine": "^1.4", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/phpstan-symfony": "^1.4", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-doctrine": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-symfony": "^2.0", "phpunit/phpunit": "^10.5", - "rector/rector": "^1.1" + "rector/rector": "^2.3" }, "suggest": { "darkwebdesign/symfony-addon-pack": "All Symfony add-ons bundled together", diff --git a/symfony-addon-transformers/phpstan.dist.neon b/symfony-addon-transformers/phpstan.dist.neon index d58d3b6..59d1334 100644 --- a/symfony-addon-transformers/phpstan.dist.neon +++ b/symfony-addon-transformers/phpstan.dist.neon @@ -4,3 +4,5 @@ parameters: paths: - 'src' - 'tests' + + treatPhpDocTypesAsCertain: false diff --git a/symfony-addon-transformers/rector.php b/symfony-addon-transformers/rector.php index da41b57..aa82129 100644 --- a/symfony-addon-transformers/rector.php +++ b/symfony-addon-transformers/rector.php @@ -3,16 +3,17 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\Set\ValueObject\LevelSetList; return RectorConfig::configure() ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', ]) - ->withSets([ - LevelSetList::UP_TO_PHP_82, - ]) - ->withImportNames( - importShortClasses: false, - ); + ->withPhpSets() + ->withAttributesSets() + ->withPreparedSets(phpunitCodeQuality: true, doctrineCodeQuality: true, symfonyCodeQuality: true, symfonyConfigs: true) + ->withComposerBased(doctrine: true, phpunit: true, symfony: true) + ->withImportNames(importShortClasses: false, removeUnusedImports: true) + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/symfony-addon-transformers/src/BooleanToValueTransformer.php b/symfony-addon-transformers/src/BooleanToValueTransformer.php index dfd827f..4cd38cd 100644 --- a/symfony-addon-transformers/src/BooleanToValueTransformer.php +++ b/symfony-addon-transformers/src/BooleanToValueTransformer.php @@ -29,7 +29,7 @@ /** * @template R of string|int|float|bool * - * @template-implements DataTransformerInterface + * @implements DataTransformerInterface * * @author Raymond Schouten * diff --git a/symfony-addon-transformers/src/EntityToIdentifierTransformer.php b/symfony-addon-transformers/src/EntityToIdentifierTransformer.php index 1ca2e7a..af828db 100644 --- a/symfony-addon-transformers/src/EntityToIdentifierTransformer.php +++ b/symfony-addon-transformers/src/EntityToIdentifierTransformer.php @@ -40,7 +40,7 @@ * @template T of object * @template R of mixed * - * @template-implements DataTransformerInterface + * @implements DataTransformerInterface * * @author Raymond Schouten * @@ -52,6 +52,7 @@ class EntityToIdentifierTransformer implements DataTransformerInterface private readonly string $className; /** @var ObjectRepository */ private readonly ObjectRepository $repository; + /** @var ClassMetadata */ private readonly ClassMetadata $metadata; /** diff --git a/symfony-addon-transformers/tests/BooleanToValueTransformerTest.php b/symfony-addon-transformers/tests/BooleanToValueTransformerTest.php index 7cb658b..0007b05 100644 --- a/symfony-addon-transformers/tests/BooleanToValueTransformerTest.php +++ b/symfony-addon-transformers/tests/BooleanToValueTransformerTest.php @@ -33,7 +33,7 @@ * @internal */ #[CoversClass(BooleanToValueTransformer::class)] -class BooleanToValueTransformerTest extends TestCase +final class BooleanToValueTransformerTest extends TestCase { #[DataProvider('providerTrueFalseValue')] public function testTransform(mixed $trueValue, mixed $falseValue): void @@ -125,46 +125,40 @@ public function testReverseTransformInvalidValue(mixed $trueValue, mixed $falseV } /** - * @return array + * @return \Iterator */ - public static function providerTrueFalseValue(): array + public static function providerTrueFalseValue(): \Iterator { - return [ - 'true/false' => [true, false], - 'yes/no' => ['yes', 'no'], - 'on/off' => ['on', 'off'], - '1/0' => ['1', '0'], - '1/2' => [1, 2], - '1.3/2.7' => [1.3, 2.7], - ]; + yield 'true/false' => [true, false]; + yield 'yes/no' => ['yes', 'no']; + yield 'on/off' => ['on', 'off']; + yield '1/0' => ['1', '0']; + yield '1/2' => [1, 2]; + yield '1.3/2.7' => [1.3, 2.7]; } /** - * @return array + * @return \Iterator */ - public static function providerNoBool(): array + public static function providerNoBool(): \Iterator { - return [ - 'int' => [1], - 'float' => [1.2], - 'string' => ['foo'], - 'array' => [['foo', 'bar']], - 'object' => [new \stdClass()], - 'resource' => [tmpfile()], - 'callable' => [function () {}], - ]; + yield 'int' => [1]; + yield 'float' => [1.2]; + yield 'string' => ['foo']; + yield 'array' => [['foo', 'bar']]; + yield 'object' => [new \stdClass()]; + yield 'resource' => [tmpfile()]; + yield 'callable' => [function (): void {}]; } /** - * @return array + * @return \Iterator */ - public static function providerNoScalar(): array + public static function providerNoScalar(): \Iterator { - return [ - 'array' => [['foo', 'bar']], - 'object' => [new \stdClass()], - 'resource' => [tmpfile()], - 'callable' => [function () {}], - ]; + yield 'array' => [['foo', 'bar']]; + yield 'object' => [new \stdClass()]; + yield 'resource' => [tmpfile()]; + yield 'callable' => [function (): void {}]; } } diff --git a/symfony-addon-transformers/tests/EntityToIdentifierTransformerTest.php b/symfony-addon-transformers/tests/EntityToIdentifierTransformerTest.php index 93b2288..fa1900d 100644 --- a/symfony-addon-transformers/tests/EntityToIdentifierTransformerTest.php +++ b/symfony-addon-transformers/tests/EntityToIdentifierTransformerTest.php @@ -40,7 +40,7 @@ * @internal */ #[CoversClass(EntityToIdentifierTransformer::class)] -class EntityToIdentifierTransformerTest extends TestCase +final class EntityToIdentifierTransformerTest extends TestCase { private City $entity; /** @var class-string */ @@ -52,8 +52,6 @@ class EntityToIdentifierTransformerTest extends TestCase private ObjectManager $entityManager; /** @var ObjectRepository&MockObject */ private ObjectRepository $repository; - /** @var ClassMetadata&MockObject */ - private ClassMetadata $metadata; protected function setUp(): void { @@ -66,13 +64,13 @@ protected function setUp(): void $this->entityManager = $this->createMock(ObjectManager::class); $this->repository = $this->createMock(ObjectRepository::class); - $this->metadata = $this->createMock(ClassMetadata::class); + $metadata = $this->createMock(ClassMetadata::class); $this->entityManager->method('getRepository')->willReturn($this->repository); - $this->entityManager->method('getClassMetadata')->willReturn($this->metadata); + $this->entityManager->method('getClassMetadata')->willReturn($metadata); - $this->metadata->method('getName')->willReturnCallback($this->getClassName(...)); - $this->metadata->method('getIdentifierValues')->willReturnCallback($this->getIdentifier(...)); + $metadata->method('getName')->willReturnCallback($this->getClassName(...)); + $metadata->method('getIdentifierValues')->willReturnCallback($this->getIdentifier(...)); } public function getClassName(): string @@ -100,7 +98,7 @@ public function testTransform(): void public function testTransformAlias(): void { /** @var class-string $className */ - $className = 'AppBundle:City'; + $className = 'AppBundle:City'; // @phpstan-ignore varTag.nativeType $transformer = new EntityToIdentifierTransformer($this->entityManager, $className); @@ -222,31 +220,27 @@ public function testReverseTransformEntityNotFound(): void } /** - * @return array + * @return \Iterator */ - public static function providerNoObject(): array + public static function providerNoObject(): \Iterator { - return [ - 'bool' => [true], - 'int' => [1], - 'float' => [1.2], - 'string' => ['foo'], - 'array' => [['foo', 'bar']], - 'resource' => [tmpfile()], - 'callable' => [function () {}], - ]; + yield 'bool' => [true]; + yield 'int' => [1]; + yield 'float' => [1.2]; + yield 'string' => ['foo']; + yield 'array' => [['foo', 'bar']]; + yield 'resource' => [tmpfile()]; + yield 'callable' => [function (): void {}]; } /** - * @return array + * @return \Iterator */ - public static function providerNoScalar(): array - { - return [ - 'array' => [['foo', 'bar']], - 'object' => [new \stdClass()], - 'resource' => [tmpfile()], - 'callable' => [function () {}], - ]; + public static function providerNoScalar(): \Iterator + { + yield 'array' => [['foo', 'bar']]; + yield 'object' => [new \stdClass()]; + yield 'resource' => [tmpfile()]; + yield 'callable' => [function (): void {}]; } }