Skip to content

Commit 7b2ff7a

Browse files
Revert "non-falsy-string cannot be converted to 0"
1 parent aa236a7 commit 7b2ff7a

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/Type/Accessory/AccessoryNonFalsyStringType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ public function toAbsoluteNumber(): Type
184184

185185
public function toInteger(): Type
186186
{
187-
return TypeCombinator::remove(new IntegerType(), new ConstantIntegerType(0));
187+
// Do not remove `0` since `(int) '00'` is still `0`.
188+
return new IntegerType();
188189
}
189190

190191
public function toFloat(): Type

tests/PHPStan/Analyser/nsrt/bug-10893.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
function hasMicroseconds(\DateTimeInterface $value, string $str): bool
1111
{
1212
assertType('non-falsy-string&numeric-string', $str);
13-
assertType('int<min, -1>|int<1, max>', (int)$str);
14-
assertType('true', (int)$str !== 0);
13+
assertType('int', (int)$str);
14+
assertType('bool', (int)$str !== 0);
1515

1616
assertType('non-falsy-string&numeric-string', $value->format('u'));
17-
assertType('int<min, -1>|int<1, max>', (int)$value->format('u'));
18-
assertType('true', (int)$value->format('u') !== 0);
17+
assertType('int', (int)$value->format('u'));
18+
assertType('bool', (int)$value->format('u') !== 0);
1919

2020
assertType('non-falsy-string&numeric-string', $value->format('v'));
21-
assertType('int<min, -1>|int<1, max>', (int)$value->format('v'));
22-
assertType('true', (int)$value->format('v') !== 0);
21+
assertType('int', (int)$value->format('v'));
22+
assertType('bool', (int)$value->format('v') !== 0);
2323

2424
assertType('float', $value->format('u') * 1e-6);
2525
assertType('float', $value->format('v') * 1e-3);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function doStrings($nonEmpty, $nonFalsy, $numeric, $literal, $lower, $upper) {
177177
$this->foo = $nonEmpty;
178178
assertType('int', $this->foo);
179179
$this->foo = $nonFalsy;
180-
assertType('int<min, -1>|int<1, max>', $this->foo);
180+
assertType('int', $this->foo);
181181
$this->foo = $numeric;
182182
assertType('int', $this->foo);
183183
$this->foo = $literal;
@@ -706,4 +706,3 @@ public function __toString(): string {
706706
return 'Foo';
707707
}
708708
}
709-

tests/PHPStan/Analyser/nsrt/non-falsy-string.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Foo {
1111
* @param truthy-string $truthyString
1212
*/
1313
public function bar($nonFalseyString, $truthyString) {
14-
assertType('int<min, -1>|int<1, max>', (int) $nonFalseyString);
14+
assertType('int', (int) $nonFalseyString); // Do not remove `0` since `(int) '00'` is still `0`
1515
// truthy-string is an alias for non-falsy-string
1616
assertType('non-falsy-string', $truthyString);
1717
}

0 commit comments

Comments
 (0)