Skip to content

Commit

Permalink
Merge branch refs/heads/1.11.x into 1.12.x
Browse files Browse the repository at this point in the history
  • Loading branch information
phpstan-bot authored Aug 22, 2024
2 parents 9e4d5b1 + 1a97440 commit c5e0443
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ public function specifyTypesInCondition(
$argType = $scope->getType($expr->right->getArgs()[0]->value);
if ($argType->isString()->yes()) {
$accessory = new AccessoryNonEmptyStringType();
if ($leftType instanceof ConstantIntegerType && $leftType->getValue() >= 2) {

if (IntegerRangeType::createAllGreaterThanOrEqualTo(2 - $offset)->isSuperTypeOf($leftType)->yes()) {
$accessory = new AccessoryNonFalsyStringType();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/nsrt/bug-10952b.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public function test(): void
$string = $this->getString();

if (1 < mb_strlen($string)) {
assertType('non-empty-string', $string);
assertType('non-falsy-string', $string);
} else {
assertType("string", $string);
}

if (mb_strlen($string) > 1) {
assertType('non-empty-string', $string);
assertType('non-falsy-string', $string);
} else {
assertType("string", $string);
}
Expand Down
54 changes: 54 additions & 0 deletions tests/PHPStan/Analyser/nsrt/strlen-int-range.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php // lint >= 7.2

namespace StrlenIntRange;

use function PHPStan\Testing\assertType;

/**
* @param int<0, 3> $zeroToThree
* @param int<2, 3> $twoOrThree
* @param int<2, max> $twoOrMore
* @param int<min, 3> $maxThree
* @param int<10, 11> $tenOrEleven
*/
function doFoo(string $s, $zeroToThree, $twoOrThree, $twoOrMore, int $maxThree, $tenOrEleven): void
{
if (strlen($s) >= $zeroToThree) {
assertType('string', $s);
}
if (strlen($s) > $zeroToThree) {
assertType('non-empty-string', $s);
}

if (strlen($s) >= $twoOrThree) {
assertType('non-falsy-string', $s);
}
if (strlen($s) > $twoOrThree) {
assertType('non-falsy-string', $s);
}

if (strlen($s) > $twoOrMore) {
assertType('non-falsy-string', $s);
}

$oneOrMore = $twoOrMore-1;
if (strlen($s) > $oneOrMore) {
assertType('non-falsy-string', $s);
}
if (strlen($s) >= $oneOrMore) {
assertType('non-empty-string', $s);
}
if (strlen($s) <= $oneOrMore) {
assertType('string', $s);
} else {
assertType('non-falsy-string', $s);
}

if (strlen($s) > $maxThree) {
assertType('string', $s);
}

if (strlen($s) > $tenOrEleven) {
assertType('non-falsy-string', $s);
}
}

0 comments on commit c5e0443

Please sign in to comment.