Skip to content

Commit 1bea3db

Browse files
committed
more precise ints
1 parent b2a27a8 commit 1bea3db

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/Type/Constant/ConstantIntegerType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function toArrayKey(): Type
9999
public function toCoercedArgumentType(bool $strictTypes): Type
100100
{
101101
if (!$strictTypes) {
102-
return TypeCombinator::union(new IntegerType(), new FloatType(), new StringType(), new BooleanType());
102+
return TypeCombinator::union($this, $this->toFloat(), $this->toString(), $this->toBoolean());
103103
}
104104

105105
return TypeCombinator::union($this, $this->toFloat());

src/Type/IntegerType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function toArrayKey(): Type
101101
public function toCoercedArgumentType(bool $strictTypes): Type
102102
{
103103
if (!$strictTypes) {
104-
return TypeCombinator::union(new IntegerType(), new FloatType(), new StringType(), new BooleanType());
104+
return TypeCombinator::union($this, $this->toFloat(), $this->toString(), $this->toBoolean());
105105
}
106106

107107
return TypeCombinator::union($this, $this->toFloat());

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function doLorem(): void
5555

5656
public function doFloatTricky(){
5757
$this->float = 1;
58-
assertType('float', $this->float);
58+
assertType('1.0', $this->float);
5959
}
6060
}
6161

@@ -210,13 +210,13 @@ class FooIntString
210210
public function doFoo(int $b): void
211211
{
212212
$this->foo = $b;
213-
assertType('string', $this->foo); // could be numeric-string
213+
assertType('lowercase-string&numeric-string&uppercase-string', $this->foo);
214214
}
215215

216216
public function doBar(): void
217217
{
218218
$this->foo = 1;
219-
assertType('string', $this->foo); // could be numeric-string
219+
assertType("'1'", $this->foo);
220220
}
221221
}
222222

@@ -231,14 +231,14 @@ class FooIntRangeString
231231
public function doFoo(int $b): void
232232
{
233233
$this->foo = $b;
234-
assertType('string', $this->foo); // could be numeric-string
234+
assertType("'10'|'5'|'6'|'7'|'8'|'9'", $this->foo);
235235
}
236236

237237
public function doBar(): void
238238
{
239239
$i = rand(5, 10);
240240
$this->foo = $i;
241-
assertType('string', $this->foo); // could be numeric-string
241+
assertType("'10'|'5'|'6'|'7'|'8'|'9'", $this->foo); // could be numeric-string
242242
}
243243
}
244244

@@ -250,7 +250,7 @@ class FooNullableIntString
250250
public function doFoo(?int $b): void
251251
{
252252
$this->foo = $b;
253-
assertType('string', $this->foo); // could be numeric-string
253+
assertType('lowercase-string&numeric-string&uppercase-string', $this->foo); // could be numeric-string
254254
}
255255

256256
public function doBar(): void

0 commit comments

Comments
 (0)