File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
tests/PHPStan/Rules/Comparison Expand file tree Collapse file tree 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
10161016 $ this ->analyse ([__DIR__ . '/data/bug-11019.php ' ], []);
10171017 }
10181018
1019+ public function testBug12946 (): void
1020+ {
1021+ $ this ->analyse ([__DIR__ . '/data/bug-12946.php ' ], []);
1022+ }
1023+
10191024}
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