Skip to content

Commit cab49eb

Browse files
authored
Fix strlen($x) > $n === true negation
1 parent 4e5020d commit cab49eb

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ public function specifyTypesInCondition(
269269
&& $leftType->isInteger()->yes()
270270
) {
271271
if (
272-
$context->truthy() && (IntegerRangeType::createAllGreaterThanOrEqualTo(1 - $offset)->isSuperTypeOf($leftType)->yes())
273-
|| ($context->falsey() && (new ConstantIntegerType(1 - $offset))->isSuperTypeOf($leftType)->yes())
272+
$context->true() && (IntegerRangeType::createAllGreaterThanOrEqualTo(1 - $offset)->isSuperTypeOf($leftType)->yes())
273+
|| ($context->false() && (new ConstantIntegerType(1 - $offset))->isSuperTypeOf($leftType)->yes())
274274
) {
275275
$argType = $scope->getType($expr->right->getArgs()[0]->value);
276276
if ($argType->isString()->yes()) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10952c;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
public function getString(): string
10+
{
11+
return 'hallo';
12+
}
13+
14+
public function test(): void
15+
{
16+
$string = $this->getString();
17+
18+
if ((strlen($string) > 1) === true) {
19+
assertType('non-empty-string', $string);
20+
} else {
21+
assertType("string", $string);
22+
}
23+
24+
match (true) {
25+
(strlen($string) > 1) => assertType('non-empty-string', $string),
26+
default => assertType("string", $string),
27+
};
28+
29+
}
30+
}

0 commit comments

Comments
 (0)