Skip to content

Commit 82a592c

Browse files
committed
OperatorRuleHelper - allow mixed
1 parent b8d2ddc commit 82a592c

7 files changed

+11
-36
lines changed

src/Rules/Operators/OperatorRuleHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPStan\Type\FloatType;
66
use PHPStan\Type\IntegerType;
7+
use PHPStan\Type\MixedType;
78
use PHPStan\Type\Type;
89
use PHPStan\Type\UnionType;
910

@@ -12,6 +13,10 @@ class OperatorRuleHelper
1213

1314
public static function isValidForArithmeticOperation(Type $leftType, Type $rightType): bool
1415
{
16+
if ($leftType instanceof MixedType || $rightType instanceof MixedType) {
17+
return true;
18+
}
19+
1520
$acceptedType = new UnionType([new IntegerType(), new FloatType()]);
1621

1722
return $acceptedType->isSuperTypeOf($leftType)->yes() && $acceptedType->isSuperTypeOf($rightType)->yes();

tests/Rules/Operators/OperandsInArithmeticAdditionTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ public function testRule(): void
4343
'Only numeric types or arrays are allowed in arithmetic addition.',
4444
30,
4545
],
46-
[
47-
'Only numeric types or arrays are allowed in arithmetic addition.',
48-
30,
49-
],
50-
[
51-
'Only numeric types or arrays are allowed in arithmetic addition.',
52-
30,
53-
],
5446
]);
5547
}
5648

tests/Rules/Operators/OperandsInArithmeticDivisionTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ public function testRule(): void
4343
'Only numeric types are allowed in arithmetic division.',
4444
69,
4545
],
46-
[
47-
'Only numeric types are allowed in arithmetic division.',
48-
69,
49-
],
50-
[
51-
'Only numeric types are allowed in arithmetic division.',
52-
69,
53-
],
5446
]);
5547
}
5648

tests/Rules/Operators/OperandsInArithmeticExponentiationTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ public function testRule(): void
4343
'Only numeric types are allowed in arithmetic exponentiation.',
4444
82,
4545
],
46-
[
47-
'Only numeric types are allowed in arithmetic exponentiation.',
48-
82,
49-
],
5046
]);
5147
}
5248

tests/Rules/Operators/OperandsInArithmeticMultiplicationTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ public function testRule(): void
4343
'Only numeric types are allowed in arithmetic multiplication.',
4444
56,
4545
],
46-
[
47-
'Only numeric types are allowed in arithmetic multiplication.',
48-
56,
49-
],
50-
[
51-
'Only numeric types are allowed in arithmetic multiplication.',
52-
56,
53-
],
5446
]);
5547
}
5648

tests/Rules/Operators/OperandsInArithmeticSubtractionTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ public function testRule(): void
4343
'Only numeric types are allowed in arithmetic subtraction.',
4444
43,
4545
],
46-
[
47-
'Only numeric types are allowed in arithmetic subtraction.',
48-
43,
49-
],
50-
[
51-
'Only numeric types are allowed in arithmetic subtraction.',
52-
43,
53-
],
5446
]);
5547
}
5648

tests/Rules/Operators/data/operators.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,9 @@
9393
$int % $null;
9494
$int % $float % $string % $null;
9595
$array % $float % $array % $int;
96+
97+
function ($mixed, int $a) {
98+
$mixed + $mixed;
99+
$mixed + $a;
100+
$a + $mixed;
101+
};

0 commit comments

Comments
 (0)