Skip to content

Commit

Permalink
refactor(driver): use instanceof checks for correct phpdoc node
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Jul 16, 2024
1 parent d0a24b7 commit 13292e1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\TypeAliasTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
Expand Down Expand Up @@ -408,15 +409,15 @@ private function getPhpstanType(\ReflectionClass $declaringClass, string $typeHi
$self = $this;

foreach ($phpDocNode->children as $node) {
if ($node instanceof PhpDocTagNode && '@phpstan-type' === $node->name) {
$phpstanType = (string) $node->value;
if ($node instanceof PhpDocTagNode && $node->value instanceof TypeAliasTagValueNode) {
$phpstanType = $node->value->__toString();
preg_match_all(self::PHPSTAN_ARRAY_SHAPE, $phpstanType, $foundPhpstanArray);
if (isset($foundPhpstanArray[1][0]) && $foundPhpstanArray[1][0] === $typeHint) {
if (isset($foundPhpstanArray[0][0]) && $node->value->alias === $typeHint) {
return 'array';
}

preg_match_all(self::PHPSTAN_ARRAY_TYPE, $phpstanType, $foundPhpstanArray);
if (isset($foundPhpstanArray[2][0]) && $foundPhpstanArray[1][0] === $typeHint) {
if (isset($foundPhpstanArray[0][0]) && $node->value->alias === $typeHint) {
$types = explode(',', $foundPhpstanArray[2][0]);

return sprintf('array<%s>', implode(
Expand Down

0 comments on commit 13292e1

Please sign in to comment.