diff --git a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php index 09123d7331..cd0fa17e76 100644 --- a/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php @@ -476,4 +476,31 @@ public function testBug6356b(): void ]); } + public function testIntegerRangesAndConstants(): void + { + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/int-ranges-and-constants.php'], [ + [ + 'Property IntegerRangesAndConstants\HelloWorld::$i (0|1|3) does not accept int<0, 3>.', + 17, + ], + [ + 'Property IntegerRangesAndConstants\HelloWorld::$x (int<0, 3>) does not accept 0|1|2|3|string.', + 42, + ], + [ + 'Property IntegerRangesAndConstants\HelloWorld::$x (int<0, 3>) does not accept 0|1|2|3|bool.', + 43, + ], + [ + 'Property IntegerRangesAndConstants\HelloWorld::$x (int<0, 3>) does not accept 0|1|3|bool.', + 44, + ], + [ + 'Property IntegerRangesAndConstants\HelloWorld::$x (int<0, 3>) does not accept 0|1|3|4.', + 45, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Properties/data/int-ranges-and-constants.php b/tests/PHPStan/Rules/Properties/data/int-ranges-and-constants.php new file mode 100644 index 0000000000..3aaa0fc82f --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/int-ranges-and-constants.php @@ -0,0 +1,56 @@ +i = random_int(0, 3); + $this->j = random_int(0, 3); + $this->k = random_int(0, 3); + $this->l = random_int(0, 3); + } + + /** + * @var int<0,3> + */ + public $x = 0; + + /** + * @param 0| $a + * @param 0|1 $b + * @param 0|1|3 $c + * @param 0|1|2|3|string $j + * @param 0|1|bool|2|3 $k + * @param 0|1|bool|3 $l + * @param 0|1|3|4 $m + */ + public function test2($a, $b, $c, $j, $k, $l, $m): void { + $this->x = $a; + $this->x = $b; + $this->x = $c; + + $this->x = $j; + $this->x = $k; + $this->x = $l; + $this->x = $m; + } + + const I_1=1; + const I_2=2; + + /** @param int-mask $flag */ + public function sayHello($flag): void + { + $this->x = $flag; + } +}