Skip to content

Commit 4299805

Browse files
committed
isDecimalIntegerString test
1 parent 818433d commit 4299805

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

src/Type/ArrayType.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PHPStan\ShouldNotHappenException;
1313
use PHPStan\TrinaryLogic;
1414
use PHPStan\Type\Accessory\AccessoryArrayListType;
15-
use PHPStan\Type\Accessory\AccessoryDecimalIntegerStringType;
1615
use PHPStan\Type\Accessory\HasOffsetValueType;
1716
use PHPStan\Type\Accessory\NonEmptyArrayType;
1817
use PHPStan\Type\Constant\ConstantArrayType;
@@ -206,10 +205,10 @@ public function getIterableKeyType(): Type
206205
{
207206
$keyType = $this->keyType;
208207
if ($keyType instanceof MixedType && !$keyType instanceof TemplateMixedType) {
209-
return new BenevolentUnionType([new IntegerType(), new IntersectionType([new StringType(), new AccessoryDecimalIntegerStringType(inverse: true)])]);
208+
return new BenevolentUnionType([new IntegerType(), new StringType()]);
210209
}
211210
if ($keyType instanceof StrictMixedType) {
212-
return new BenevolentUnionType([new IntegerType(), new IntersectionType([new StringType(), new AccessoryDecimalIntegerStringType(inverse: true)])]);
211+
return new BenevolentUnionType([new IntegerType(), new StringType()]);
213212
}
214213

215214
return $keyType;

src/Type/Constant/ConstantStringType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public function isNumericString(): TrinaryLogic
331331

332332
public function isDecimalIntegerString(): TrinaryLogic
333333
{
334-
return parent::isDecimalIntegerString();
334+
return TrinaryLogic::createFromBoolean((string) (int) $this->value === $this->value);
335335
}
336336

337337
public function isNonEmptyString(): TrinaryLogic

tests/PHPStan/Type/Constant/ConstantStringTypeTest.php

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,63 @@ public function testSetInvalidValue(): void
185185
$this->assertInstanceOf(ErrorType::class, $result);
186186
}
187187

188-
public function test
188+
public static function dataIsDecimalIntegerString(): iterable
189+
{
190+
yield [
191+
'0',
192+
TrinaryLogic::createYes(),
193+
];
194+
yield [
195+
'1',
196+
TrinaryLogic::createYes(),
197+
];
198+
yield [
199+
'1234',
200+
TrinaryLogic::createYes(),
201+
];
202+
yield [
203+
'-1',
204+
TrinaryLogic::createYes(),
205+
];
206+
yield [
207+
'+1',
208+
TrinaryLogic::createNo(),
209+
];
210+
yield [
211+
'00',
212+
TrinaryLogic::createNo(),
213+
];
214+
yield [
215+
'01',
216+
TrinaryLogic::createNo(),
217+
];
218+
yield [
219+
'18E+3',
220+
TrinaryLogic::createNo(),
221+
];
222+
yield [
223+
'1.2',
224+
TrinaryLogic::createNo(),
225+
];
226+
yield [
227+
'1,3',
228+
TrinaryLogic::createNo(),
229+
];
230+
yield [
231+
'foo',
232+
TrinaryLogic::createNo(),
233+
];
234+
yield [
235+
'1foo',
236+
TrinaryLogic::createNo(),
237+
];
238+
}
239+
240+
#[DataProvider('dataIsDecimalIntegerString')]
241+
public function testIsDecimalIntegerString(string $value, TrinaryLogic $expected): void
242+
{
243+
$type = new ConstantStringType($value);
244+
$this->assertSame($expected->describe(), $type->isDecimalIntegerString()->describe());
245+
}
189246

190247
}

0 commit comments

Comments
 (0)