Skip to content

Commit 9f2df2c

Browse files
committed
Added regression test
1 parent f66ec0c commit 9f2df2c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

+5
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

Comments
 (0)