Skip to content

Commit 92a665c

Browse files
committed
Simplify isNumeric
1 parent 1a56b90 commit 92a665c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Rule/ForbidArithmeticOperationOnNonNumberRule.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,13 @@ private function processBinary(
137137

138138
private function isNumeric(Type $type): bool
139139
{
140-
$int = new IntegerType();
141-
$float = new FloatType();
142-
$bcNumber = new ObjectType('BcMath\Number');
143-
$intOrFloatOrBcNumber = new UnionType([$int, $float, $bcNumber]);
140+
$numericUnion = new UnionType([
141+
new IntegerType(),
142+
new FloatType(),
143+
new ObjectType('BcMath\Number'),
144+
]);
144145

145-
return $int->isSuperTypeOf($type)->yes()
146-
|| $float->isSuperTypeOf($type)->yes()
147-
|| $bcNumber->isSuperTypeOf($type)->yes()
148-
|| $intOrFloatOrBcNumber->isSuperTypeOf($type)->yes()
146+
return $numericUnion->isSuperTypeOf($type)->yes()
149147
|| ($this->allowNumericString && $type->isNumericString()->yes());
150148
}
151149

tests/Rule/data/ForbidArithmeticOperationOnNonNumberRule/code.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public function testUnions(
130130
-$intFloat;
131131
-$intFloatString; // error: Using - over non-number (float|int|string)
132132
-$intArray; // error: Using - over non-number (array|int)
133+
134+
$intString - $intArray; // error: Using - over non-number (int|string - array|int)
133135
}
134136

135137
/**

0 commit comments

Comments
 (0)