Skip to content

Commit

Permalink
OperandsInArithmeticAdditionRule - allow benevolent unions of arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 11, 2023
1 parent 2ffa76a commit 361f75b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -7,7 +7,7 @@
],
"require": {
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.9.0"
"phpstan/phpstan": "^1.9.7"
},
"require-dev": {
"nikic/php-parser": "^4.13.0",
Expand Down
7 changes: 2 additions & 5 deletions src/Rules/Operators/OperandsInArithmeticAdditionRule.php
Expand Up @@ -7,9 +7,8 @@
use PhpParser\Node\Expr\BinaryOp\Plus;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\VerbosityLevel;
use function count;
use function sprintf;

class OperandsInArithmeticAdditionRule implements Rule
Expand All @@ -36,9 +35,7 @@ public function processNode(Node $node, Scope $scope): array
{
$leftType = $scope->getType($node->left);
$rightType = $scope->getType($node->right);
$mixedArrayType = new ArrayType(new MixedType(), new MixedType());

if ($mixedArrayType->isSuperTypeOf($leftType)->yes() && $mixedArrayType->isSuperTypeOf($rightType)->yes()) {
if (count($leftType->getArrays()) > 0 && count($rightType->getArrays()) > 0) {
return [];
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Rules/Operators/data/operators.php
Expand Up @@ -113,3 +113,7 @@ function (array $array, int $int, $mixed) {
/** @var numeric-string $numericString */
$numericString = doFoo();
$numericString + 1;

function (\ReflectionClass $ref): void {
print_r(class_parents($ref->getName()) + class_implements($ref->getName()));
};

0 comments on commit 361f75b

Please sign in to comment.