Skip to content

Commit c5e0443

Browse files
authored
Merge branch refs/heads/1.11.x into 1.12.x
2 parents 9e4d5b1 + 1a97440 commit c5e0443

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

src/Analyser/TypeSpecifier.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ public function specifyTypesInCondition(
316316
$argType = $scope->getType($expr->right->getArgs()[0]->value);
317317
if ($argType->isString()->yes()) {
318318
$accessory = new AccessoryNonEmptyStringType();
319-
if ($leftType instanceof ConstantIntegerType && $leftType->getValue() >= 2) {
319+
320+
if (IntegerRangeType::createAllGreaterThanOrEqualTo(2 - $offset)->isSuperTypeOf($leftType)->yes()) {
320321
$accessory = new AccessoryNonFalsyStringType();
321322
}
322323

tests/PHPStan/Analyser/nsrt/bug-10952b.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public function test(): void
1616
$string = $this->getString();
1717

1818
if (1 < mb_strlen($string)) {
19-
assertType('non-empty-string', $string);
19+
assertType('non-falsy-string', $string);
2020
} else {
2121
assertType("string", $string);
2222
}
2323

2424
if (mb_strlen($string) > 1) {
25-
assertType('non-empty-string', $string);
25+
assertType('non-falsy-string', $string);
2626
} else {
2727
assertType("string", $string);
2828
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php // lint >= 7.2
2+
3+
namespace StrlenIntRange;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param int<0, 3> $zeroToThree
9+
* @param int<2, 3> $twoOrThree
10+
* @param int<2, max> $twoOrMore
11+
* @param int<min, 3> $maxThree
12+
* @param int<10, 11> $tenOrEleven
13+
*/
14+
function doFoo(string $s, $zeroToThree, $twoOrThree, $twoOrMore, int $maxThree, $tenOrEleven): void
15+
{
16+
if (strlen($s) >= $zeroToThree) {
17+
assertType('string', $s);
18+
}
19+
if (strlen($s) > $zeroToThree) {
20+
assertType('non-empty-string', $s);
21+
}
22+
23+
if (strlen($s) >= $twoOrThree) {
24+
assertType('non-falsy-string', $s);
25+
}
26+
if (strlen($s) > $twoOrThree) {
27+
assertType('non-falsy-string', $s);
28+
}
29+
30+
if (strlen($s) > $twoOrMore) {
31+
assertType('non-falsy-string', $s);
32+
}
33+
34+
$oneOrMore = $twoOrMore-1;
35+
if (strlen($s) > $oneOrMore) {
36+
assertType('non-falsy-string', $s);
37+
}
38+
if (strlen($s) >= $oneOrMore) {
39+
assertType('non-empty-string', $s);
40+
}
41+
if (strlen($s) <= $oneOrMore) {
42+
assertType('string', $s);
43+
} else {
44+
assertType('non-falsy-string', $s);
45+
}
46+
47+
if (strlen($s) > $maxThree) {
48+
assertType('string', $s);
49+
}
50+
51+
if (strlen($s) > $tenOrEleven) {
52+
assertType('non-falsy-string', $s);
53+
}
54+
}

0 commit comments

Comments
 (0)