File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedConstructorParamRector/Fixture
rules/DeadCode/Rector/ClassMethod
tests/Issues/IssuePropertyPromoRemoveDelegatingParent/config Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \DeadCode \Rector \ClassMethod \RemoveUnusedConstructorParamRector \Fixture ;
4+
5+ use Rector \Contract \Rector \RectorInterface ;
6+
7+ #[\Attribute]
8+ final class SkipAttributeMarker
9+ {
10+ /**
11+ * @param RectorInterface $someClass
12+ */
13+ public function __construct (string $ someClass )
14+ {
15+ }
16+ }
Original file line number Diff line number Diff line change 44
55namespace Rector \DeadCode \Rector \ClassMethod ;
66
7+ use PhpParser \Comment \Doc ;
78use PhpParser \Node ;
89use PhpParser \Node \Stmt \Class_ ;
910use PhpParser \Node \Stmt \ClassMethod ;
@@ -91,11 +92,17 @@ public function refactor(Node $node): ?Node
9192
9293 $ interfaces = $ classReflection ->getInterfaces ();
9394 foreach ($ interfaces as $ interface ) {
95+ // parameters are contract required → skip
9496 if ($ interface ->hasNativeMethod (MethodName::CONSTRUCT )) {
9597 return null ;
9698 }
9799 }
98100
101+ // attributes can be used as markers
102+ if ($ classReflection ->isAttributeClass () && $ constructorClassMethod ->getDocComment () instanceof Doc) {
103+ return null ;
104+ }
105+
99106 $ changedConstructorClassMethod = $ this ->classMethodParamRemover ->processRemoveParams ($ constructorClassMethod );
100107 if (! $ changedConstructorClassMethod instanceof ClassMethod) {
101108 return null ;
Original file line number Diff line number Diff line change 88 ->withRules ([
99 ClassPropertyAssignToConstructorPromotionRector::class,
1010 RemoveParentDelegatingConstructorRector::class,
11- ]);
11+ ]);
You can’t perform that action at this time.
0 commit comments