Skip to content

Commit 361f75b

Browse files
committed
OperandsInArithmeticAdditionRule - allow benevolent unions of arrays
1 parent 2ffa76a commit 361f75b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.2 || ^8.0",
10-
"phpstan/phpstan": "^1.9.0"
10+
"phpstan/phpstan": "^1.9.7"
1111
},
1212
"require-dev": {
1313
"nikic/php-parser": "^4.13.0",

Diff for: src/Rules/Operators/OperandsInArithmeticAdditionRule.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
use PhpParser\Node\Expr\BinaryOp\Plus;
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Rules\Rule;
10-
use PHPStan\Type\ArrayType;
11-
use PHPStan\Type\MixedType;
1210
use PHPStan\Type\VerbosityLevel;
11+
use function count;
1312
use function sprintf;
1413

1514
class OperandsInArithmeticAdditionRule implements Rule
@@ -36,9 +35,7 @@ public function processNode(Node $node, Scope $scope): array
3635
{
3736
$leftType = $scope->getType($node->left);
3837
$rightType = $scope->getType($node->right);
39-
$mixedArrayType = new ArrayType(new MixedType(), new MixedType());
40-
41-
if ($mixedArrayType->isSuperTypeOf($leftType)->yes() && $mixedArrayType->isSuperTypeOf($rightType)->yes()) {
38+
if (count($leftType->getArrays()) > 0 && count($rightType->getArrays()) > 0) {
4239
return [];
4340
}
4441

Diff for: tests/Rules/Operators/data/operators.php

+4
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,7 @@ function (array $array, int $int, $mixed) {
113113
/** @var numeric-string $numericString */
114114
$numericString = doFoo();
115115
$numericString + 1;
116+
117+
function (\ReflectionClass $ref): void {
118+
print_r(class_parents($ref->getName()) + class_implements($ref->getName()));
119+
};

0 commit comments

Comments
 (0)