Skip to content

Commit 4428a5a

Browse files
committed
Arithmetic operators - do not report duplicitly what's already reported as a bug in PHPStan core
1 parent bfa7b29 commit 4428a5a

8 files changed

+5
-114
lines changed

src/Rules/Operators/OperatorRuleHelper.php

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

33
namespace PHPStan\Rules\Operators;
44

5+
use PHPStan\Type\ErrorType;
56
use PHPStan\Type\FloatType;
67
use PHPStan\Type\IntegerType;
78
use PHPStan\Type\MixedType;
@@ -17,6 +18,10 @@ public static function isValidForArithmeticOperation(Type $type): bool
1718
return true;
1819
}
1920

21+
if ($type->toNumber() instanceof ErrorType) {
22+
return true;
23+
}
24+
2025
$acceptedType = new UnionType([new IntegerType(), new FloatType()]);
2126

2227
return $acceptedType->isSuperTypeOf($type)->yes();

tests/Levels/data/arithmeticOperators-0.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
[
2-
{
3-
"message": "Only numeric types are allowed in +, string given on the left side.",
4-
"line": 26,
5-
"ignorable": true
6-
},
72
{
83
"message": "Only numeric types are allowed in +, string given on the left side.",
94
"line": 27,
105
"ignorable": true
116
},
12-
{
13-
"message": "Only numeric types are allowed in +, int|string given on the left side.",
14-
"line": 28,
15-
"ignorable": true
16-
},
177
{
188
"message": "Only numeric types are allowed in +, int|string given on the left side.",
199
"line": 29,

tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ public function testRule(): void
1919
'Only numeric types are allowed in +, string given on the right side.',
2020
25,
2121
],
22-
[
23-
'Only numeric types are allowed in +, array given on the right side.',
24-
26,
25-
],
26-
[
27-
'Only numeric types are allowed in +, stdClass given on the right side.',
28-
27,
29-
],
3022
[
3123
'Only numeric types are allowed in +, null given on the right side.',
3224
28,
@@ -39,22 +31,6 @@ public function testRule(): void
3931
'Only numeric types are allowed in +, string given on the right side.',
4032
29,
4133
],
42-
[
43-
'Only numeric types are allowed in +, array given on the right side.',
44-
30,
45-
],
46-
[
47-
'Only numeric types are allowed in +, array given on the left side.',
48-
30,
49-
],
50-
[
51-
'Only numeric types are allowed in +, string given on the right side.',
52-
101,
53-
],
54-
[
55-
'Only numeric types are allowed in +, string given on the left side.',
56-
102,
57-
],
5834
]);
5935
}
6036

tests/Rules/Operators/OperandsInArithmeticDivisionRuleTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ public function testRule(): void
1919
'Only numeric types are allowed in /, string given on the right side.',
2020
64,
2121
],
22-
[
23-
'Only numeric types are allowed in /, array given on the right side.',
24-
65,
25-
],
26-
[
27-
'Only numeric types are allowed in /, stdClass given on the right side.',
28-
66,
29-
],
3022
[
3123
'Only numeric types are allowed in /, null given on the right side.',
3224
67,
@@ -39,14 +31,6 @@ public function testRule(): void
3931
'Only numeric types are allowed in /, string given on the right side.',
4032
68,
4133
],
42-
[
43-
'Only numeric types are allowed in /, array given on the right side.',
44-
69,
45-
],
46-
[
47-
'Only numeric types are allowed in /, array given on the left side.',
48-
69,
49-
],
5034
]);
5135
}
5236

tests/Rules/Operators/OperandsInArithmeticExponentiationRuleTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ public function testRule(): void
1919
'Only numeric types are allowed in **, string given on the right side.',
2020
77,
2121
],
22-
[
23-
'Only numeric types are allowed in **, array given on the right side.',
24-
78,
25-
],
26-
[
27-
'Only numeric types are allowed in **, stdClass given on the right side.',
28-
79,
29-
],
3022
[
3123
'Only numeric types are allowed in **, null given on the right side.',
3224
80,
@@ -39,14 +31,6 @@ public function testRule(): void
3931
'Only numeric types are allowed in **, null given on the right side.',
4032
81,
4133
],
42-
[
43-
'Only numeric types are allowed in **, array given on the left side.',
44-
82,
45-
],
46-
[
47-
'Only numeric types are allowed in **, array given on the left side.',
48-
82,
49-
],
5034
]);
5135
}
5236

tests/Rules/Operators/OperandsInArithmeticModuloRuleTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ public function testRule(): void
1919
'Only numeric types are allowed in %, string given on the right side.',
2020
90,
2121
],
22-
[
23-
'Only numeric types are allowed in %, array given on the right side.',
24-
91,
25-
],
26-
[
27-
'Only numeric types are allowed in %, stdClass given on the right side.',
28-
92,
29-
],
3022
[
3123
'Only numeric types are allowed in %, null given on the right side.',
3224
93,
@@ -39,14 +31,6 @@ public function testRule(): void
3931
'Only numeric types are allowed in %, string given on the right side.',
4032
94,
4133
],
42-
[
43-
'Only numeric types are allowed in %, array given on the right side.',
44-
95,
45-
],
46-
[
47-
'Only numeric types are allowed in %, array given on the left side.',
48-
95,
49-
],
5034
]);
5135
}
5236

tests/Rules/Operators/OperandsInArithmeticMultiplicationRuleTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ public function testRule(): void
1919
'Only numeric types are allowed in *, string given on the right side.',
2020
51,
2121
],
22-
[
23-
'Only numeric types are allowed in *, array given on the right side.',
24-
52,
25-
],
26-
[
27-
'Only numeric types are allowed in *, stdClass given on the right side.',
28-
53,
29-
],
3022
[
3123
'Only numeric types are allowed in *, null given on the right side.',
3224
54,
@@ -39,14 +31,6 @@ public function testRule(): void
3931
'Only numeric types are allowed in *, string given on the right side.',
4032
55,
4133
],
42-
[
43-
'Only numeric types are allowed in *, array given on the right side.',
44-
56,
45-
],
46-
[
47-
'Only numeric types are allowed in *, array given on the left side.',
48-
56,
49-
],
5034
]);
5135
}
5236

tests/Rules/Operators/OperandsInArithmeticSubtractionRuleTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ public function testRule(): void
1919
'Only numeric types are allowed in -, string given on the right side.',
2020
38,
2121
],
22-
[
23-
'Only numeric types are allowed in -, array given on the right side.',
24-
39,
25-
],
26-
[
27-
'Only numeric types are allowed in -, stdClass given on the right side.',
28-
40,
29-
],
3022
[
3123
'Only numeric types are allowed in -, null given on the right side.',
3224
41,
@@ -39,14 +31,6 @@ public function testRule(): void
3931
'Only numeric types are allowed in -, string given on the right side.',
4032
42,
4133
],
42-
[
43-
'Only numeric types are allowed in -, array given on the right side.',
44-
43,
45-
],
46-
[
47-
'Only numeric types are allowed in -, array given on the left side.',
48-
43,
49-
],
5034
]);
5135
}
5236

0 commit comments

Comments
 (0)