forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-12244.php
More file actions
77 lines (64 loc) · 1.47 KB
/
bug-12244.php
File metadata and controls
77 lines (64 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php // lint >= 8.1
declare(strict_types = 1);
namespace Bug12244;
use function PHPStan\Testing\assertType;
enum X: string {
case A = 'a';
case B = 'b';
case C = 'c';
/** @return ($this is self::A ? int : null) */
public function get(): ?int {
return ($this === self::A) ? 123 : null;
}
public function doSomething(): void {
if ($this !== self::A) {
assertType('$this(Bug12244\X~Bug12244\X::A)', $this);
assertType('null', $this->get());
} else {
assertType('int', $this->get());
}
if ($this !== self::B && $this !== self::C) {
assertType('int', $this->get());
}
}
public static function doSomethingFor(X $x): void {
if ($x !== self::A) {
assertType('Bug12244\X~Bug12244\X::A', $x);
assertType('null', $x->get());
} else {
assertType('int', $x->get());
}
if ($x !== self::B && $x !== self::C) {
assertType('int', $x->get());
}
}
}
enum Y: string {
case A = 'a';
case B = 'b';
case C = 'c';
/** @param-out ($this is self::A ? int : null) $i */
public function get(?int &$i): void {
($this === self::A) ? $i=null : $i=123;
}
public function doSomething(): void {
$i = 0;
if ($this !== self::A) {
$this->get($i);
assertType('null', $i); // null
} else {
$this->get($i);
assertType('int', $i); // int
}
}
public static function doSomethingFor(Y $x): void {
$i = 0;
if ($x !== self::A) {
$x->get($i);
assertType('null', $i); // null
} else {
$x->get($i);
assertType('int', $i); // int
}
}
}