File tree 2 files changed +61
-1
lines changed
tests/PHPStan/Analyser/nsrt
2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 16
16
use PHPStan \Type \TypeTraverser ;
17
17
use function array_key_exists ;
18
18
use function count ;
19
+ use function is_bool ;
19
20
use function strtolower ;
20
21
use function substr ;
21
22
@@ -200,8 +201,26 @@ public static function resolvePhpDocBlockForMethod(
200
201
array $ newPositionalParameterNames ,
201
202
): self
202
203
{
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
+
203
222
$ docBlocksFromParents = self ::resolveParentPhpDocBlocks (
204
- self :: getParentReflections ( $ classReflection ) ,
223
+ $ parentReflections ,
205
224
$ methodName ,
206
225
'hasNativeMethod ' ,
207
226
'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