File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
tests/PHPStan/Rules/Methods Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -3608,6 +3608,25 @@ public function testBug9141(): void
36083608 $ this ->analyse ([__DIR__ . '/data/bug-9141.php ' ], []);
36093609 }
36103610
3611+ public function testBug3589 (): void
3612+ {
3613+ $ this ->checkThisOnly = false ;
3614+ $ this ->checkNullables = true ;
3615+ $ this ->checkUnionTypes = true ;
3616+ $ this ->checkExplicitMixed = true ;
3617+
3618+ $ this ->analyse ([__DIR__ . '/data/bug-3589.php ' ], [
3619+ [
3620+ 'Parameter #1 $fooId of method FooRepository::load() expects Id<Foo>, Id<Bar> given. ' ,
3621+ 33 ,
3622+ ],
3623+ [
3624+ 'Parameter #1 $fooId of method FooRepository::load() expects Id<Foo>, Id<mixed> given. ' ,
3625+ 39 ,
3626+ ],
3627+ ]);
3628+ }
3629+
36113630 public function testBug3396 (): void
36123631 {
36133632 $ this ->checkThisOnly = false ;
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ class Foo{}
4+ class Bar{}
5+
6+ /**
7+ * @template Tpl
8+ */
9+ class Id{}
10+
11+ class FooRepository
12+ {
13+ /**
14+ * @param Id<Foo> $fooId
15+ */
16+ public function load (Id $ fooId ): Foo
17+ {
18+ // ...
19+ return new Foo ;
20+ }
21+ }
22+
23+ $ fooRepository = new FooRepository ;
24+
25+ // Expected behavior: no error
26+ /** @var Id<Foo> */
27+ $ fooId = new Id ;
28+ $ fooRepository ->load ($ fooId );
29+
30+ // Expected behavior: error on line 33
31+ /** @var Id<Bar> */
32+ $ barId = new Id ;
33+ $ fooRepository ->load ($ barId );
34+
35+ // Expected behavior: errors
36+ // - line 38 - Template Tpl is not specified
37+ // - line 39 - Parameter #1 fooId of method FooRepository::load() expects Id<Foo>, nonspecified Id given.
38+ $ unknownId = new Id ;
39+ $ fooRepository ->load ($ unknownId );
You can’t perform that action at this time.
0 commit comments