diff --git a/config/sets/symfony/symfony8/symfony81.php b/config/sets/symfony/symfony8/symfony81.php index 6eace7ee..055f8356 100644 --- a/config/sets/symfony/symfony8/symfony81.php +++ b/config/sets/symfony/symfony8/symfony81.php @@ -7,4 +7,5 @@ // @see https://github.com/symfony/symfony/blob/8.1/UPGRADE-8.1.md return static function (RectorConfig $rectorConfig): void { $rectorConfig->import(__DIR__ . '/symfony81/symfony81-dependency-injection.php'); + $rectorConfig->import(__DIR__ . '/symfony81/symfony81-uid.php'); }; diff --git a/config/sets/symfony/symfony8/symfony81/symfony81-uid.php b/config/sets/symfony/symfony8/symfony81/symfony81-uid.php new file mode 100644 index 00000000..1e7acc90 --- /dev/null +++ b/config/sets/symfony/symfony8/symfony81/symfony81-uid.php @@ -0,0 +1,10 @@ +rules([AddFormatArgumentToIsValidRector::class]); +}; diff --git a/rules-tests/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector/AddFormatArgumentToIsValidRectorTest.php b/rules-tests/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector/AddFormatArgumentToIsValidRectorTest.php new file mode 100644 index 00000000..6f44c742 --- /dev/null +++ b/rules-tests/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector/AddFormatArgumentToIsValidRectorTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/rules-tests/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector/Fixture/add_format_argument_to_is_valid.php.inc b/rules-tests/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector/Fixture/add_format_argument_to_is_valid.php.inc new file mode 100644 index 00000000..f6e899b4 --- /dev/null +++ b/rules-tests/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector/Fixture/add_format_argument_to_is_valid.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/rules-tests/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector/config/configured_rule.php b/rules-tests/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector/config/configured_rule.php new file mode 100644 index 00000000..2b554ee5 --- /dev/null +++ b/rules-tests/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(AddFormatArgumentToIsValidRector::class); +}; diff --git a/rules/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector.php b/rules/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector.php new file mode 100644 index 00000000..cbd8ffd1 --- /dev/null +++ b/rules/Symfony81/Rector/StaticCall/AddFormatArgumentToIsValidRector.php @@ -0,0 +1,94 @@ +isName($node->class, 'Symfony\Component\Uid\Ulid')) { + return null; + } + + if (! $this->isName($node->name, 'isValid')) { + return null; + } + + if ($node->isFirstClassCallable()) { + return null; + } + + if (\count($node->args) !==1) { + return null; + } + + $node->args[] = new Arg( + new ClassConstFetch(new FullyQualified(SymfonyClass::ULID_CLASS), 'FORMAT_BASE_32') + ); + + return $node; + } +} diff --git a/src/Enum/SymfonyClass.php b/src/Enum/SymfonyClass.php index aa884560..891ff8b9 100644 --- a/src/Enum/SymfonyClass.php +++ b/src/Enum/SymfonyClass.php @@ -105,4 +105,6 @@ final class SymfonyClass public const string ABSTRACT_TYPE_EXTENSION = 'Symfony\Component\Form\AbstractTypeExtension'; public const string ABSTRACT_TYPE = 'Symfony\Component\Form\AbstractType'; + + public const string ULID_CLASS = 'Symfony\Component\Uid\Ulid'; } diff --git a/src/Set/SetProvider/Symfony8SetProvider.php b/src/Set/SetProvider/Symfony8SetProvider.php index 9bca284f..a05fa7f5 100644 --- a/src/Set/SetProvider/Symfony8SetProvider.php +++ b/src/Set/SetProvider/Symfony8SetProvider.php @@ -29,6 +29,12 @@ public function provide(): array '8.1', __DIR__ . '/../../../config/sets/symfony/symfony8/symfony81/symfony81-dependency-injection.php' ), + new ComposerTriggeredSet( + SetGroup::SYMFONY, + 'symfony/uid', + '8.1', + __DIR__ . '/../../../config/sets/symfony/symfony8/symfony81/symfony81-uid.php' + ), ]; } } diff --git a/src/Set/SymfonySetList.php b/src/Set/SymfonySetList.php index 5f0ceda3..61a04dbe 100644 --- a/src/Set/SymfonySetList.php +++ b/src/Set/SymfonySetList.php @@ -171,6 +171,11 @@ final class SymfonySetList */ public const string SYMFONY_80 = __DIR__ . '/../../config/sets/symfony/symfony8/symfony80.php'; + /** + * @deprecated Set list are too generic and do not handle package differences. Use ->withComposerBased(symfony: true) instead + */ + public const string SYMFONY_81 = __DIR__ . '/../../config/sets/symfony/symfony8/symfony81.php'; + public const string SYMFONY_CODE_QUALITY = __DIR__ . '/../../config/sets/symfony/symfony-code-quality.php'; public const string SYMFONY_CONSTRUCTOR_INJECTION = __DIR__ . '/../../config/sets/symfony/symfony-constructor-injection.php';