File tree Expand file tree Collapse file tree
rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture
rules/TypeDeclaration/Rector/ClassMethod Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclaration \Rector \ClassMethod \ArrayParamTypeByMethodCallTypeRector \Fixture ;
4+
5+ trait SkipTrait
6+ {
7+ public function go ($ value )
8+ {
9+ $ this ->use ($ value );
10+ }
11+
12+ private function use (array $ value ): void
13+ {
14+ }
15+ }
Original file line number Diff line number Diff line change 1313use PhpParser \Node \Param ;
1414use PhpParser \Node \Stmt \ClassMethod ;
1515use PhpParser \Node \Stmt \Function_ ;
16+ use PHPStan \Analyser \Scope ;
1617use PHPStan \Type \Type ;
1718use Rector \NodeTypeResolver \Node \AttributeKey ;
1819use Rector \NodeTypeResolver \PHPStan \Type \TypeFactory ;
@@ -99,6 +100,12 @@ abstract protected function isMatchingParamType(Type $type): bool;
99100
100101 private function shouldSkipClassMethod (ClassMethod $ classMethod ): bool
101102 {
103+ // trait method can be used in a class that requires a contract type, adding a param type would break it
104+ $ scope = $ classMethod ->getAttribute (AttributeKey::SCOPE );
105+ if ($ scope instanceof Scope && $ scope ->isInTrait ()) {
106+ return true ;
107+ }
108+
102109 // user-guarded class: adding a param type here would break its child classes
103110 if ($ this ->parentClassMethodTypeOverrideGuard ->isTypeGuardedClass ($ classMethod )) {
104111 return true ;
You can’t perform that action at this time.
0 commit comments