Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f615b1a

Browse files
staabmondrejmirtes
authored andcommitted
non-falsy-string cannot be converted to 0
1 parent 3854cbc commit f615b1a

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

‎src/Type/Accessory/AccessoryNonFalsyStringType.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use PHPStan\Type\Traits\TruthyBooleanTypeTrait;
3232
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
3333
use PHPStan\Type\Type;
34+
use PHPStan\Type\TypeCombinator;
3435
use PHPStan\Type\UnionType;
3536
use PHPStan\Type\VerbosityLevel;
3637

@@ -183,7 +184,7 @@ public function toAbsoluteNumber(): Type
183184

184185
public function toInteger(): Type
185186
{
186-
return new IntegerType();
187+
return TypeCombinator::remove(new IntegerType(), newConstantIntegerType(0));
187188
}
188189

189190
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', (int)$str);
14-
assertType('bool', (int)$str !== 0);
13+
assertType('int<min, -1>|int<1, max>', (int)$str);
14+
assertType('true', (int)$str !== 0);
1515

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

2020
assertType('non-falsy-string&numeric-string', $value->format('v'));
21-
assertType('int', (int)$value->format('v'));
22-
assertType('bool', (int)$value->format('v') !== 0);
21+
assertType('int<min, -1>|int<1, max>', (int)$value->format('v'));
22+
assertType('true', (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/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', (int) $nonFalseyString);
14+
assertType('int<min, -1>|int<1, max>', (int) $nonFalseyString);
1515
// truthy-string is an alias for non-falsy-string
1616
assertType('non-falsy-string', $truthyString);
1717
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /