File tree Expand file tree Collapse file tree
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -148,11 +148,10 @@ public function intersect(Assertions $other): self
148148 private static function getAssertKey (AssertTag $ assert ): string
149149 {
150150 return sprintf (
151- '%s-%s-%s-%s ' ,
151+ '%s-%s-%s ' ,
152152 $ assert ->getParameter ()->describe (),
153153 $ assert ->getIf (),
154154 $ assert ->isNegated () ? '1 ' : '0 ' ,
155- $ assert ->isEquality () ? '1 ' : '0 ' ,
156155 );
157156 }
158157
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.0
2+
3+ namespace Bug14108b ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ class Foo
8+ {
9+ public function __construct (private ?string $ param )
10+ {
11+ }
12+
13+ public function getParam (): ?string
14+ {
15+ return $ this ->param ;
16+ }
17+
18+ /**
19+ * @phpstan-assert !null $this->getParam()
20+ */
21+ public function narrowGetParam (): void
22+ {
23+ }
24+ }
25+
26+ class Bar
27+ {
28+ public function __construct (private ?int $ param )
29+ {
30+ }
31+
32+ public function getParam (): ?int
33+ {
34+ return $ this ->param ;
35+ }
36+
37+ /**
38+ * @phpstan-assert int $this->getParam()
39+ */
40+ public function narrowGetParam (): void
41+ {
42+ }
43+ }
44+
45+ function test (Foo |Bar $ fooOrBar ): void
46+ {
47+ assertType ('int|string|null ' , $ fooOrBar ->getParam ());
48+
49+ $ fooOrBar ->narrowGetParam ();
50+
51+ assertType ('int|string|null ' , $ fooOrBar ->getParam ());
52+ }
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.0
2+
3+ namespace Bug14108c ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ class Foo
8+ {
9+ public function __construct (private ?string $ param )
10+ {
11+ }
12+
13+ public function getParam (): ?string
14+ {
15+ return $ this ->param ;
16+ }
17+
18+ /**
19+ * @phpstan-assert =string $this->getParam()
20+ */
21+ public function narrowGetParam (): void
22+ {
23+ }
24+ }
25+
26+ class Bar
27+ {
28+ public function __construct (private ?int $ param )
29+ {
30+ }
31+
32+ public function getParam (): ?int
33+ {
34+ return $ this ->param ;
35+ }
36+
37+ /**
38+ * @phpstan-assert int $this->getParam()
39+ */
40+ public function narrowGetParam (): void
41+ {
42+ }
43+ }
44+
45+ function test (Foo |Bar $ fooOrBar ): void
46+ {
47+ assertType ('int|string|null ' , $ fooOrBar ->getParam ());
48+
49+ $ fooOrBar ->narrowGetParam ();
50+
51+ assertType ('int|string ' , $ fooOrBar ->getParam ());
52+ }
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.0
2+
3+ namespace Bug14108d ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ class Foo
8+ {
9+ public function __construct (private ?string $ param )
10+ {
11+ }
12+
13+ public function getParam (): ?string
14+ {
15+ return $ this ->param ;
16+ }
17+
18+ /**
19+ * @phpstan-assert-if-true string $this->getParam()
20+ */
21+ public function narrowGetParam (): bool
22+ {
23+ }
24+ }
25+
26+ class Bar
27+ {
28+ public function __construct (private ?int $ param )
29+ {
30+ }
31+
32+ public function getParam (): ?int
33+ {
34+ return $ this ->param ;
35+ }
36+
37+ /**
38+ * @phpstan-assert int $this->getParam()
39+ */
40+ public function narrowGetParam (): void
41+ {
42+ }
43+ }
44+
45+ function test (Foo |Bar $ fooOrBar ): void
46+ {
47+ assertType ('int|string|null ' , $ fooOrBar ->getParam ());
48+
49+ $ fooOrBar ->narrowGetParam ();
50+
51+ assertType ('int|string|null ' , $ fooOrBar ->getParam ());
52+
53+ if ($ fooOrBar ->narrowGetParam ()) {
54+ assertType ('int|string|null ' , $ fooOrBar ->getParam ()); // could be 'int|string'
55+ } else {
56+ assertType ('int|string|null ' , $ fooOrBar ->getParam ());
57+ }
58+ assertType ('int|string|null ' , $ fooOrBar ->getParam ());
59+ }
You can’t perform that action at this time.
0 commit comments