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