Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 18c0b6e

Browse files
OperatorRuleHelper - allow benevolent union types that contain numeric types
1 parent 1ec1d04 commit 18c0b6e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

‎src/Rules/Operators/OperatorRuleHelper.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ function (Type $type) use ($acceptedType): bool {
6565
return true;
6666
}
6767

68-
return $acceptedType->isSuperTypeOf($type)->yes();
68+
$isSuperType = $acceptedType->isSuperTypeOf($type);
69+
if ($type instanceof \PHPStan\Type\BenevolentUnionType) {
70+
return !$isSuperType->no();
71+
}
72+
73+
return $isSuperType->yes();
6974
}
7075

7176
}

‎tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public function testRule(): void
3636
'Only numeric types are allowed in +, string given on the right side.',
3737
29,
3838
],
39+
[
40+
'Only numeric types are allowed in +, (array<int, string>|false) given on the left side.',
41+
110,
42+
],
3943
]);
4044
}
4145

‎tests/Rules/Operators/data/operators.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,11 @@ function ($mixed, int $a, string $b) {
101101
$mixed + $b;
102102
$b + $mixed;
103103
};
104+
105+
function (array $array, int $int, $mixed) {
106+
foreach ($array as $i => $val) {
107+
$i + $int;
108+
}
109+
110+
explode($mixed, $mixed) + $int;
111+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /