diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedConstructorParamRector/Fixture/skip_attribute_marker.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedConstructorParamRector/Fixture/skip_attribute_marker.php.inc new file mode 100644 index 00000000000..37573cbe5cd --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedConstructorParamRector/Fixture/skip_attribute_marker.php.inc @@ -0,0 +1,16 @@ +getInterfaces(); foreach ($interfaces as $interface) { + // parameters are contract required → skip if ($interface->hasNativeMethod(MethodName::CONSTRUCT)) { return null; } } + // attributes can be used as markers + if ($classReflection->isAttributeClass() && $constructorClassMethod->getDocComment() instanceof Doc) { + return null; + } + $changedConstructorClassMethod = $this->classMethodParamRemover->processRemoveParams($constructorClassMethod); if (! $changedConstructorClassMethod instanceof ClassMethod) { return null; diff --git a/tests/Issues/IssuePropertyPromoRemoveDelegatingParent/config/configured_rule.php b/tests/Issues/IssuePropertyPromoRemoveDelegatingParent/config/configured_rule.php index 75e42bde090..374e00d4f13 100644 --- a/tests/Issues/IssuePropertyPromoRemoveDelegatingParent/config/configured_rule.php +++ b/tests/Issues/IssuePropertyPromoRemoveDelegatingParent/config/configured_rule.php @@ -8,4 +8,4 @@ ->withRules([ ClassPropertyAssignToConstructorPromotionRector::class, RemoveParentDelegatingConstructorRector::class, - ]); \ No newline at end of file + ]);