From dcc538e4a16c0a20e06cdb414dfcf388d39ee6e0 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 10 Aug 2026 19:26:55 +0200 Subject: [PATCH] [deprecation] Deprecate AddSensitiveParameterAttributeRector, as matching parameters by name is vague and risky --- ...dSensitiveParameterAttributeRectorTest.php | 28 ------------- .../apply_attribute_to_functions.php.inc | 20 ---------- .../apply_attribute_to_methods.php.inc | 26 ------------- ...nsitive_parameter_attribute_exists.php.inc | 13 ------- .../config/configured_rule.php | 15 ------- .../AddSensitiveParameterAttributeRector.php | 39 +++++-------------- 6 files changed, 10 insertions(+), 131 deletions(-) delete mode 100644 rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/AddSensitiveParameterAttributeRectorTest.php delete mode 100644 rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/apply_attribute_to_functions.php.inc delete mode 100644 rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/apply_attribute_to_methods.php.inc delete mode 100644 rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/skip_sensitive_parameter_attribute_exists.php.inc delete mode 100644 rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/config/configured_rule.php diff --git a/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/AddSensitiveParameterAttributeRectorTest.php b/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/AddSensitiveParameterAttributeRectorTest.php deleted file mode 100644 index b2f8001902e..00000000000 --- a/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/AddSensitiveParameterAttributeRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -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/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/apply_attribute_to_functions.php.inc b/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/apply_attribute_to_functions.php.inc deleted file mode 100644 index 29779005428..00000000000 --- a/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/apply_attribute_to_functions.php.inc +++ /dev/null @@ -1,20 +0,0 @@ - ------ - diff --git a/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/apply_attribute_to_methods.php.inc b/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/apply_attribute_to_methods.php.inc deleted file mode 100644 index 5c8827f5413..00000000000 --- a/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/apply_attribute_to_methods.php.inc +++ /dev/null @@ -1,26 +0,0 @@ - ------ - diff --git a/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/skip_sensitive_parameter_attribute_exists.php.inc b/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/skip_sensitive_parameter_attribute_exists.php.inc deleted file mode 100644 index 1176c32a4ba..00000000000 --- a/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/Fixture/skip_sensitive_parameter_attribute_exists.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/config/configured_rule.php b/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/config/configured_rule.php deleted file mode 100644 index f59f03dbde3..00000000000 --- a/rules-tests/Php82/Rector/Param/AddSensitiveParameterAttributeRector/config/configured_rule.php +++ /dev/null @@ -1,15 +0,0 @@ -phpVersion(PhpVersionFeature::SENSITIVE_PARAMETER_ATTRIBUTE); - - $rectorConfig->ruleWithConfiguration(AddSensitiveParameterAttributeRector::class, [ - AddSensitiveParameterAttributeRector::SENSITIVE_PARAMETERS => ['password'], - ]); -}; diff --git a/rules/Php82/Rector/Param/AddSensitiveParameterAttributeRector.php b/rules/Php82/Rector/Param/AddSensitiveParameterAttributeRector.php index 7578c57cc3a..0a510171320 100644 --- a/rules/Php82/Rector/Param/AddSensitiveParameterAttributeRector.php +++ b/rules/Php82/Rector/Param/AddSensitiveParameterAttributeRector.php @@ -5,43 +5,31 @@ namespace Rector\Php82\Rector\Param; use PhpParser\Node; -use PhpParser\Node\Attribute; -use PhpParser\Node\AttributeGroup; -use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Param; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Rector\Contract\Rector\ConfigurableRectorInterface; -use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -use Webmozart\Assert\Assert; /** - * @see \Rector\Tests\Php82\Rector\Param\AddSensitiveParameterAttributeRector\AddSensitiveParameterAttributeRectorTest + * @deprecated This rule is deprecated, as it relies on a provided variable name list. Matching parameters by name is vague and risky, as the same name can hold a non-sensitive value. Add the #[\SensitiveParameter] attribute per case instead. */ -final class AddSensitiveParameterAttributeRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface +final class AddSensitiveParameterAttributeRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface, DeprecatedInterface { - public const string SENSITIVE_PARAMETERS = 'sensitive_parameters'; - /** - * @var string[] + * @api */ - private array $sensitiveParameters = []; - - public function __construct( - private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer - ) { - } + public const string SENSITIVE_PARAMETERS = 'sensitive_parameters'; /** * @param array $configuration */ public function configure(array $configuration): void { - Assert::allString($configuration[self::SENSITIVE_PARAMETERS] ?? []); - $this->sensitiveParameters = (array) ($configuration[self::SENSITIVE_PARAMETERS] ?? []); } public function getNodeTypes(): array @@ -54,17 +42,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Param { - if (! $this->isNames($node, $this->sensitiveParameters)) { - return null; - } - - if ($this->phpAttributeAnalyzer->hasPhpAttribute($node, 'SensitiveParameter')) { - return null; - } - - $node->attrGroups[] = new AttributeGroup([new Attribute(new FullyQualified('SensitiveParameter'))]); - - return $node; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as matching sensitive parameters by name is vague and risky. Add the #[\SensitiveParameter] attribute per case instead', + self::class + )); } public function getRuleDefinition(): RuleDefinition