Skip to content

Commit 2270051

Browse files
committed
Fix detection of shadowed trait methods
1 parent 2e08c9f commit 2270051

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

src/Analyser/NodeScopeResolver.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -4473,8 +4473,20 @@ private function processTraitUse(Node\Stmt\TraitUse $node, MutatingScope $classS
44734473
if (!isset($this->analysedFiles[$fileName])) {
44744474
continue;
44754475
}
4476+
$adaptations = [];
4477+
foreach ($node->adaptations as $adaptation) {
4478+
if ($adaptation->trait === null) {
4479+
$adaptations[] = $adaptation;
4480+
continue;
4481+
}
4482+
if ($adaptation->trait->toLowerString() !== $trait->toLowerString()) {
4483+
continue;
4484+
}
4485+
4486+
$adaptations[] = $adaptation;
4487+
}
44764488
$parserNodes = $this->parser->parseFile($fileName);
4477-
$this->processNodesForTraitUse($parserNodes, $traitReflection, $classScope, $node->adaptations, $nodeCallback);
4489+
$this->processNodesForTraitUse($parserNodes, $traitReflection, $classScope, $adaptations, $nodeCallback);
44784490
}
44794491
}
44804492

tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,18 @@ public function testBug7803(): void
7272
]);
7373
}
7474

75+
public function testBug10377(): void
76+
{
77+
$this->analyse([__DIR__ . '/data/bug-10377.php'], [
78+
[
79+
'Dumped type: array<string, mixed>',
80+
22,
81+
],
82+
[
83+
'Dumped type: array<string, mixed>',
84+
34,
85+
],
86+
]);
87+
}
88+
7589
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Bug10377;
4+
5+
final class WebRequest
6+
{
7+
8+
use Headers, RequestParameters {
9+
Headers::addAdditionalProperties as addAdditionalPropertiesHeaders;
10+
RequestParameters::addAdditionalProperties insteadof Headers;
11+
}
12+
13+
}
14+
15+
trait Headers
16+
{
17+
/**
18+
* @param array<string, mixed> $additionalProperties
19+
*/
20+
public function addAdditionalProperties(array $additionalProperties): void
21+
{
22+
\PHPStan\dumpType($additionalProperties);
23+
}
24+
}
25+
26+
trait RequestParameters
27+
{
28+
29+
/**
30+
* @param array<string, mixed> $additionalProperties
31+
*/
32+
public function addAdditionalProperties(array $additionalProperties): void
33+
{
34+
\PHPStan\dumpType($additionalProperties);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)