Skip to content

Commit

Permalink
[NodeTypeResolver] Reduce AstResolver usage on ArrayTypeAnalyzer (#5096)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Sep 30, 2023
1 parent 3c1035b commit 8a3fddf
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions packages/NodeTypeResolver/TypeAnalyzer/ArrayTypeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,13 @@ private function isPropertyFetchWithArrayDefault(Expr $expr): bool
return false;
}

/** @var ClassLike $classLike */
$classLike = $this->astResolver->resolveClassFromClassReflection($classReflection);
$propertyName = $this->nodeNameResolver->getName($expr->name);

if ($propertyName === null) {
return false;
}

// A. local property
$property = $classLike->getProperty($propertyName);
if ($property instanceof Property) {
$propertyProperty = $property->props[0];
return $propertyProperty->default instanceof Array_;
}

// B. another object property
$phpPropertyReflection = $this->reflectionResolver->resolvePropertyReflectionFromPropertyFetch($expr);
if ($phpPropertyReflection instanceof PhpPropertyReflection) {
$reflectionProperty = $phpPropertyReflection->getNativeReflection();
$betterReflection = $reflectionProperty->getBetterReflection();
$defaultValueExpr = $betterReflection->getDefaultValueExpression();

if (! $defaultValueExpr instanceof Expr) {
return false;
}

$defaultValueType = $this->nodeTypeResolver->getType($defaultValueExpr);
return $defaultValueType->isArray()
->yes();
return $defaultValueExpr instanceof Array_;
}

return false;
Expand Down

0 comments on commit 8a3fddf

Please sign in to comment.