Skip to content

Commit 044dfcf

Browse files
zonuexeondrejmirtes
authored andcommitted
Make AccessoryNonFalsyStringType::toInteger() return IntegerType instead of non-zero
1 parent 7961f7a commit 044dfcf

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

src/Type/Accessory/AccessoryNonFalsyStringType.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ public function toNumber(): Type
171171

172172
public function toInteger(): Type
173173
{
174-
return new UnionType([
175-
IntegerRangeType::fromInterval(null, -1),
176-
IntegerRangeType::fromInterval(1, null),
177-
]);
174+
return new IntegerType();
178175
}
179176

180177
public function toFloat(): Type

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ public function dataFileAsserts(): iterable
14631463
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6613.php');
14641464
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10187.php');
14651465
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10834.php');
1466+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10893.php');
14661467
}
14671468

14681469
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10893;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param non-falsy-string $nonfalsy
9+
*/
10+
function hasMicroseconds(\DateTimeInterface $value, string $nonfalsy): bool
11+
{
12+
assertType('non-falsy-string', $value->format('u'));
13+
assertType('int', (int)$value->format('u'));
14+
assertType('bool', (int)$value->format('u') !== 0);
15+
assertType('non-falsy-string', $nonfalsy);
16+
assertType('int', (int)$nonfalsy);
17+
assertType('bool', (int)$nonfalsy !== 0);
18+
19+
return (int) $value->format('u') !== 0;
20+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Foo {
1010
* @param truthy-string $truthyString
1111
*/
1212
public function bar($nonFalseyString, $truthyString) {
13-
assertType('int<min, -1>|int<1, max>', (int) $nonFalseyString);
13+
assertType('int', (int) $nonFalseyString);
1414
// truthy-string is an alias for non-falsy-string
1515
assertType('non-falsy-string', $truthyString);
1616
}

0 commit comments

Comments
 (0)