File tree Expand file tree Collapse file tree 2 files changed +61
-1
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 1616use PHPStan \Type \TypeTraverser ;
1717use function array_key_exists ;
1818use function count ;
19+ use function is_bool ;
1920use function strtolower ;
2021use function substr ;
2122
@@ -200,8 +201,26 @@ public static function resolvePhpDocBlockForMethod(
200201 array $ newPositionalParameterNames ,
201202 ): self
202203 {
204+ $ parentReflections = self ::getParentReflections ($ classReflection );
205+ foreach ($ classReflection ->getTraits (true ) as $ traitReflection ) {
206+ if (!$ traitReflection ->hasNativeMethod ($ methodName )) {
207+ continue ;
208+ }
209+ $ traitMethod = $ traitReflection ->getNativeMethod ($ methodName );
210+ $ abstract = $ traitMethod ->isAbstract ();
211+ if (is_bool ($ abstract )) {
212+ if (!$ abstract ) {
213+ continue ;
214+ }
215+ } elseif (!$ abstract ->yes ()) {
216+ continue ;
217+ }
218+
219+ $ parentReflections [] = $ traitReflection ;
220+ }
221+
203222 $ docBlocksFromParents = self ::resolveParentPhpDocBlocks (
204- self :: getParentReflections ( $ classReflection ) ,
223+ $ parentReflections ,
205224 $ methodName ,
206225 'hasNativeMethod ' ,
207226 'getNativeMethod ' ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace InheritAbstractTraitMethodPhpDoc ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ trait FooTrait
8+ {
9+
10+ /** @return int */
11+ abstract public function doFoo ();
12+
13+ /** @return int */
14+ public function doBar ()
15+ {
16+ return 1 ;
17+ }
18+
19+ }
20+
21+ class Foo
22+ {
23+
24+ use FooTrait;
25+
26+ public function doFoo ()
27+ {
28+ return 1 ;
29+ }
30+
31+ public function doBar ()
32+ {
33+ return 1 ;
34+ }
35+
36+ }
37+
38+ function (Foo $ foo ): void {
39+ assertType ('int ' , $ foo ->doFoo ());
40+ assertType ('mixed ' , $ foo ->doBar ());
41+ };
You can’t perform that action at this time.
0 commit comments