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 361f75b

Browse files
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

‎composer.json‎

Lines changed: 1 addition & 1 deletion
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",

‎src/Rules/Operators/OperandsInArithmeticAdditionRule.php‎

Lines changed: 2 additions & 5 deletions
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

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

Lines changed: 4 additions & 0 deletions
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)

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