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 1+ <?php declare (strict_types=1 );
2+
3+ namespace Bug11441 ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ class Foo {
8+ public function getParam (): ?string {
9+ return 'foo ' ;
10+ }
11+
12+ /** @phpstan-assert !null $this->getParam() */
13+ public function checkNotNull (): void {
14+ if ($ this ->getParam () === null ) {
15+ throw new \Exception ();
16+ }
17+ }
18+ }
19+
20+ class Bar {
21+ public function getParam (): ?int {
22+ return 1 ;
23+ }
24+
25+ /** @phpstan-assert !null $this->getParam() */
26+ public function checkNotNull (): void {
27+ if ($ this ->getParam () === null ) {
28+ throw new \Exception ();
29+ }
30+ }
31+ }
32+
33+ function test (Foo |Bar $ obj ): void {
34+ assertType ('int|string|null ' , $ obj ->getParam ());
35+
36+ $ obj ->checkNotNull ();
37+
38+ assertType ('int|string ' , $ obj ->getParam ());
39+ }
You can’t perform that action at this time.
0 commit comments