Skip to content

Commit 6d616b3

Browse files
phpstan-botclaude
andcommitted
Remove redundant array structure checks in ArrayHandler
ConstantArrayType::isCallable() already validates that the array has exactly 2 elements with keys 0 and 1, so the explicit count and key checks are unnecessary when isCallable()->maybe() is used as a guard. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1101adb commit 6d616b3

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

src/Analyser/ExprHandler/ArrayHandler.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use PHPStan\Type\Type;
2424
use PHPStan\Type\TypeCombinator;
2525
use function array_merge;
26-
use function count;
2726

2827
/**
2928
* @implements ExprHandler<Array_>
@@ -48,10 +47,8 @@ public function resolveType(MutatingScope $scope, Expr $expr): Type
4847
$type = $this->initializerExprTypeResolver->getArrayType($expr, static fn (Expr $expr): Type => $scope->getType($expr));
4948

5049
if (
51-
count($expr->items) === 2
52-
&& $expr->items[0]->key === null
53-
&& $expr->items[1]->key === null
54-
&& $type->isCallable()->maybe()
50+
$type->isCallable()->maybe()
51+
&& isset($expr->items[0], $expr->items[1])
5552
) {
5653
$methodExistsCall = new FuncCall(
5754
new FullyQualified('method_exists'),

0 commit comments

Comments
 (0)