Skip to content

Commit 849343f

Browse files
phpstan-botclaude
andcommitted
Test that a repeated non-generic object type of a generic class is reported once regardless of Type instance sharing
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6db7f59 commit 849343f

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎tests/PHPStan/Rules/Methods/MissingMethodParameterTypehintRuleTest.php‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,27 @@ public function testBug14549(): void
165165

166166
public function testRepeatedIterableTypeReportedOnce(): void
167167
{
168-
// the same missing value type is reported once per parameter,
168+
// the same missing value type or generic class is reported once per parameter,
169169
// regardless of whether the occurrences share a Type instance (type alias) or not
170170
$this->analyse([__DIR__ . '/data/bug-15350.php'], [
171171
[
172172
'Method Bug15350\\Foo::inline() has parameter $a with no value type specified in iterable type array.',
173-
14,
173+
23,
174174
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
175175
],
176176
[
177177
'Method Bug15350\\Foo::alias() has parameter $a with no value type specified in iterable type array.',
178-
21,
178+
30,
179179
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
180180
],
181+
[
182+
'Method Bug15350\\Foo::inlineGeneric() has parameter $a with generic class Bug15350\\Box but does not specify its types: T',
183+
37,
184+
],
185+
[
186+
'Method Bug15350\\Foo::aliasGeneric() has parameter $a with generic class Bug15350\\Box but does not specify its types: T',
187+
44,
188+
],
181189
]);
182190
}
183191

‎tests/PHPStan/Rules/Methods/data/bug-15350.php‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

33
namespace Bug15350;
44

5+
/**
6+
* @template T
7+
*/
8+
class Box
9+
{
10+
11+
}
12+
513
/**
614
* @phpstan-type BareArr array
15+
* @phpstan-type BareBox Box
716
*/
817
class Foo
918
{
@@ -22,4 +31,18 @@ public function alias($a): void
2231
{
2332
}
2433

34+
/**
35+
* @param callable(Box): Box $a
36+
*/
37+
public function inlineGeneric($a): void
38+
{
39+
}
40+
41+
/**
42+
* @param callable(BareBox): BareBox $a
43+
*/
44+
public function aliasGeneric($a): void
45+
{
46+
}
47+
2548
}

0 commit comments

Comments
 (0)