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 ;
1011use PHPStan \PhpDocParser \Ast \PhpDoc \DeprecatedTagValueNode ;
12+ use PHPStan \Reflection \ClassReflection ;
1113use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfo ;
1214use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
1315use Rector \Configuration \Parameter \FeatureFlags ;
@@ -160,7 +162,16 @@ private function shouldSkipClassMethod(Class_ $class, ClassMethod $classMethod):
160162 return ! $ classMethod ->isPublic ();
161163 }
162164
163- return $ this ->isName ($ classMethod , MethodName::INVOKE );
165+ if ($ this ->isName ($ classMethod , MethodName::INVOKE )) {
166+ return true ;
167+ }
168+
169+ $ classReflection = $ scope ->getClassReflection ();
170+ if (! $ classReflection instanceof ClassReflection) {
171+ return false ;
172+ }
173+
174+ return $ this ->isAttributeMarkerConstructor ($ classMethod , $ classReflection );
164175 }
165176
166177 private function hasDeprecatedAnnotation (ClassMethod $ classMethod ): bool
@@ -172,4 +183,20 @@ private function hasDeprecatedAnnotation(ClassMethod $classMethod): bool
172183
173184 return $ phpDocInfo ->hasByType (DeprecatedTagValueNode::class);
174185 }
186+
187+ /**
188+ * Skip constructor in attributes as might be a marker parameter
189+ */
190+ private function isAttributeMarkerConstructor (ClassMethod $ classMethod , ClassReflection $ classReflection ): bool
191+ {
192+ if (! $ this ->isName ($ classMethod , MethodName::CONSTRUCT )) {
193+ return false ;
194+ }
195+
196+ if (! $ classReflection ->isAttributeClass ()) {
197+ return false ;
198+ }
199+
200+ return $ classMethod ->getDocComment () instanceof Doc;
201+ }
175202}
0 commit comments