diff --git a/rules-tests/Symfony61/Rector/Class_/CommandConfigureToAttributeRector/Fixture/skip_existing_attribute_with_only_options.php.inc b/rules-tests/Symfony61/Rector/Class_/CommandConfigureToAttributeRector/Fixture/skip_existing_attribute_with_only_options.php.inc new file mode 100644 index 00000000..83fcf93f --- /dev/null +++ b/rules-tests/Symfony61/Rector/Class_/CommandConfigureToAttributeRector/Fixture/skip_existing_attribute_with_only_options.php.inc @@ -0,0 +1,17 @@ +addArgument('zone', InputArgument::OPTIONAL, 'Zone'); + $this->addOption('only-local', 'l', description: 'Only local'); + } +} diff --git a/rules/Symfony61/Rector/Class_/CommandConfigureToAttributeRector.php b/rules/Symfony61/Rector/Class_/CommandConfigureToAttributeRector.php index 6a8f8587..448c9f20 100644 --- a/rules/Symfony61/Rector/Class_/CommandConfigureToAttributeRector.php +++ b/rules/Symfony61/Rector/Class_/CommandConfigureToAttributeRector.php @@ -161,12 +161,15 @@ function (Arg $arg): string { }, $attributeArgs ); + $hasChanged = false; foreach (self::METHODS_TO_ATTRIBUTE_NAMES as $methodName => $attributeName) { $resolvedExpr = $this->findAndRemoveMethodExpr($configureClassMethod, $methodName); if (! $resolvedExpr instanceof Expr) { continue; } + $hasChanged = true; + if (in_array($attributeName, $existingAttributeNames, true)) { continue; } @@ -190,8 +193,6 @@ function (Arg $arg): string { $asCommandAttribute->args = $attributeArgs; } - $hasChanged = $attributeArgs !== []; - // remove left overs foreach ((array) $configureClassMethod->stmts as $key => $stmt) { if ($this->isExpressionVariableThis($stmt)) {