Skip to content

[ComposerBased] Add JMS attribute rules to set, bond three attribute rules to package versions - #1029

Merged
TomasVotruba merged 2 commits into
mainfrom
composer-based-attribute-rules
Aug 11, 2026
Merged

[ComposerBased] Add JMS attribute rules to set, bond three attribute rules to package versions#1029
TomasVotruba merged 2 commits into
mainfrom
composer-based-attribute-rules

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Aug 11, 2026

Copy link
Copy Markdown
Member

Two JMS attribute-migration rules were missing from the composer-based Symfony set, and three attribute rules declared no ComposerPackageConstraintInterface at all. This adds the bonding to all three, and registers the two JMS rules in the set.

Versions were verified against the upstream tags, not guessed — see Version sources below.

AccessorAnnotationToAttributeRectorjms/serializer >=3.14

 use JMS\Serializer\Annotation\Accessor;

 class User
 {
-    /**
-     * @Accessor("getValue")
-     */
+    #[Accessor(getter: 'getValue')]
     private $value;
 }

AccessTypeAnnotationToAttributeRectorjms/serializer >=3.14

 use JMS\Serializer\Annotation\AccessType;

-/**
- * @AccessType("public_method")
- */
+#[AccessType(type: 'public_method')]
 class User
 {
 }

InvokableCommandInputAttributeRectorsymfony/console >=7.3, bonded but not registered

This rule gets the version constraint, but is deliberately left out of the composer-based set — the transformation is still too risky to hand to everyone running the set unattended:

 use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Argument;
+use Symfony\Component\Console\Option;

 #[AsCommand(name: 'some_name')]
-final class SomeCommand extends Command
+final class SomeCommand
 {
-    public function configure()
-    {
-        $this->addArgument('argument', InputArgument::REQUIRED, 'Argument description');
-        $this->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description');
-    }
-
-    public function execute(InputInterface $input, OutputInterface $output)
-    {
-        $someArgument = $input->getArgument('argument');
-        $someOption = $input->getOption('option');
+    public function __invoke(
+        #[Argument(name: 'argument', description: 'Argument description')]
+        string $argument,
+        #[Option(name: 'option', shortcut: 'o', mode: Option::VALUE_NONE, description: 'Option description')]
+        bool $option = false,
+    ) {
+        $someArgument = $argument;
+        $someOption = $option;

         // ...

         return Command::SUCCESS;
     }
 }

It stays opt-in via a direct $rectorConfig->rule() call, and now correctly skips itself on symfony/console below 7.3.

Version sources

  • symfony/consoleAttribute/Argument.php is absent at tag v7.2.0 and present at v7.3.0.
  • jms/serializerAccessor.php and AccessType.php gain their #[\Attribute(...)] declaration between tags 3.13.0 and 3.14.0, from Add PHP attributes support schmittjoh/serializer#1332 and #1337 (merged 1–5 Aug 2021, released in 3.14.0 on 6 Aug 2021).

Notes

  • Both JMS rules stay registered in config/sets/jms/annotations-to-attributes.php as well, so the standalone JMS set keeps working for non-Symfony users.
  • Each of the three rule tests gained a config/composer.json plus a provideComposerJsonFilePath() override, matching the existing bonded rules — neither package is in require-dev, so the version is read from the test's own composer.json. Verified the gate is live: dropping the JMS test constraint to ^3.13 makes both fixtures fail, as expected.

…composer-based set

Bond InvokableCommandInputAttributeRector to symfony/console >=7.3,
AccessorAnnotationToAttributeRector and AccessTypeAnnotationToAttributeRector
to jms/serializer >=3.14.
Still risky to run unattended; version bonding stays on the rule.
@TomasVotruba TomasVotruba changed the title [ComposerBased] Add invokable command + JMS attribute rules with version bonding [ComposerBased] Add JMS attribute rules to set, bond three attribute rules to package versions Aug 11, 2026
@TomasVotruba
TomasVotruba merged commit 0c7bed0 into main Aug 11, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the composer-based-attribute-rules branch August 11, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant