Skip to content

Commit 2f74584

Browse files
committed
FileTypeMapper - fix getting PHPDoc of abstract trait method
1 parent d2e193c commit 2f74584

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

src/Reflection/Php/PhpClassReflectionExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
676676

677677
$resolvedPhpDoc = $this->phpDocInheritanceResolver->resolvePhpDocForMethod(
678678
$docComment,
679-
$fileDeclaringClass->getFileName(),
680-
$fileDeclaringClass,
679+
$actualDeclaringClass->getFileName(),
680+
$actualDeclaringClass,
681681
$declaringTraitName,
682682
$methodReflection->getName(),
683683
$positionalParameterNames,

tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -550,4 +550,15 @@ public function testBug3580(): void
550550
$this->analyse([__DIR__ . '/data/bug-3580.php'], []);
551551
}
552552

553+
public function testOverridenAbstractTraitMethodPhpDoc(): void
554+
{
555+
if (PHP_VERSION_ID < 80000) {
556+
$this->markTestSkipped('Test requires PHP 8.0.');
557+
}
558+
559+
$this->reportMaybes = true;
560+
$this->reportStatic = true;
561+
$this->analyse([__DIR__ . '/data/overriden-abstract-trait-method-phpdoc.php'], []);
562+
}
563+
553564
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace OverridenAbstractTraitMethodPhpDoc;
4+
5+
/**
6+
* @template DataArray of array<string, mixed>
7+
*/
8+
trait FooTrait
9+
{
10+
/**
11+
* Offset checker
12+
*
13+
* @phpstan-param Offset $offset
14+
* @return bool
15+
* @template Offset of key-of<DataArray>
16+
*/
17+
abstract public function offsetExists(mixed $offset): bool;
18+
}
19+
20+
/**
21+
* @template DataArray of array<string, mixed>
22+
* @phpstan-type DataKey key-of<DataArray>
23+
* @phpstan-type DataValue DataArray[DataKey]
24+
*/
25+
class FooClass
26+
{
27+
28+
/** @phpstan-use FooTrait<DataArray> */
29+
use FooTrait;
30+
31+
/** @phpstan-var DataArray|array{} */
32+
public array $data = [];
33+
34+
35+
/**
36+
* Data checker
37+
*
38+
* @phpstan-param Offset $offset
39+
* @return bool
40+
* @template Offset of key-of<DataArray>
41+
*/
42+
public function offsetExists(mixed $offset): bool
43+
{
44+
return array_key_exists($offset, $this->data);
45+
}
46+
}

0 commit comments

Comments
 (0)