File tree 2 files changed +42
-0
lines changed
tests/PHPStan/Rules/Comparison
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -1016,4 +1016,9 @@ public function testBug11019(): void
1016
1016
$ this ->analyse ([__DIR__ . '/data/bug-11019.php ' ], []);
1017
1017
}
1018
1018
1019
+ public function testBug12946 (): void
1020
+ {
1021
+ $ this ->analyse ([__DIR__ . '/data/bug-12946.php ' ], []);
1022
+ }
1023
+
1019
1024
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug12946 ;
4
+
5
+ interface UserInterface {}
6
+ class User implements UserInterface{}
7
+
8
+ class UserMapper {
9
+ function getFromId (int $ id ) : ?UserInterface {
10
+ return $ id === 10 ? new User : null ;
11
+ }
12
+ }
13
+
14
+ class GetUserCommand {
15
+
16
+ private ?UserInterface $ currentUser = null ;
17
+
18
+ public function __construct (
19
+ private readonly UserMapper $ userMapper ,
20
+ private readonly int $ id ,
21
+ ) {
22
+ }
23
+
24
+ public function __invoke () : UserInterface {
25
+ if ( $ this ->currentUser ) {
26
+ return $ this ->currentUser ;
27
+ }
28
+
29
+ $ this ->currentUser = $ this ->userMapper ->getFromId ($ this ->id );
30
+ if ( $ this ->currentUser === null ) {
31
+ throw new \Exception ;
32
+ }
33
+
34
+ return $ this ->currentUser ;
35
+ }
36
+
37
+ }
You can’t perform that action at this time.
0 commit comments