Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Type/Accessory/AccessoryNonFalsyStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public function toAbsoluteNumber(): Type

public function toInteger(): Type
{
return TypeCombinator::remove(new IntegerType(), new ConstantIntegerType(0));
// Do not remove `0` since `(int) '00'` is still `0`.
return new IntegerType();
}

public function toFloat(): Type
Expand Down
12 changes: 6 additions & 6 deletions tests/PHPStan/Analyser/nsrt/bug-10893.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
function hasMicroseconds(\DateTimeInterface $value, string $str): bool
{
assertType('non-falsy-string&numeric-string', $str);
assertType('int<min, -1>|int<1, max>', (int)$str);
assertType('true', (int)$str !== 0);
assertType('int', (int)$str);
assertType('bool', (int)$str !== 0);

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

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

assertType('float', $value->format('u') * 1e-6);
assertType('float', $value->format('v') * 1e-3);
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/non-falsy-string.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Foo {
* @param truthy-string $truthyString
*/
public function bar($nonFalseyString, $truthyString) {
assertType('int<min, -1>|int<1, max>', (int) $nonFalseyString);
assertType('int', (int) $nonFalseyString);
// truthy-string is an alias for non-falsy-string
assertType('non-falsy-string', $truthyString);
}
Expand Down
Loading