Skip to content

Commit 4182e35

Browse files
committed
Backwards compatibility - remove Type::isNumericString()
1 parent 644f846 commit 4182e35

5 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/Type/Accessory/AccessoryNumericStringType.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function accepts(Type $type, bool $strictTypes): TrinaryLogic
4040
return CompoundTypeHelper::accepts($type, $this, $strictTypes);
4141
}
4242

43+
if (!method_exists($type, 'isNumericString')) {
44+
return TrinaryLogic::createNo();
45+
}
46+
4347
return $type->isNumericString();
4448
}
4549

@@ -49,6 +53,10 @@ public function isSuperTypeOf(Type $type): TrinaryLogic
4953
return TrinaryLogic::createYes();
5054
}
5155

56+
if (!method_exists($type, 'isNumericString')) {
57+
return TrinaryLogic::createNo();
58+
}
59+
5260
return $type->isNumericString();
5361
}
5462

@@ -58,6 +66,10 @@ public function isSubTypeOf(Type $otherType): TrinaryLogic
5866
return $otherType->isSuperTypeOf($this);
5967
}
6068

69+
if (!method_exists($otherType, 'isNumericString')) {
70+
return TrinaryLogic::createNo();
71+
}
72+
6173
return $otherType->isNumericString()
6274
->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe());
6375
}

src/Type/ArrayType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,11 @@ public static function castToArrayKeyType(Type $offsetType): Type
296296
return $offsetType;
297297
}
298298

299-
if ($offsetType instanceof FloatType || $offsetType instanceof BooleanType || $offsetType->isNumericString()->yes()) {
299+
if ($offsetType instanceof FloatType || $offsetType instanceof BooleanType) {
300+
return new IntegerType();
301+
}
302+
303+
if (method_exists($offsetType, 'isNumericString') && $offsetType->isNumericString()->yes()) {
300304
return new IntegerType();
301305
}
302306

src/Type/IntersectionType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ public function isArray(): TrinaryLogic
277277
public function isNumericString(): TrinaryLogic
278278
{
279279
return $this->intersectResults(static function (Type $type): TrinaryLogic {
280+
if (!method_exists($type, 'isNumericString')) {
281+
return TrinaryLogic::createNo();
282+
}
283+
280284
return $type->isNumericString();
281285
});
282286
}

src/Type/Type.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ public function toString(): Type;
8585

8686
public function toArray(): Type;
8787

88-
public function isNumericString(): TrinaryLogic;
89-
9088
/**
9189
* Infers template types
9290
*

src/Type/UnionType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ public function isArray(): TrinaryLogic
365365
public function isNumericString(): TrinaryLogic
366366
{
367367
return $this->unionResults(static function (Type $type): TrinaryLogic {
368+
if (!method_exists($type, 'isNumericString')) {
369+
return TrinaryLogic::createNo();
370+
}
371+
368372
return $type->isNumericString();
369373
});
370374
}

0 commit comments

Comments
 (0)