Skip to content

Fix typehint resolution - stop prefixing unions with namespace #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/Parser/NodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@
}
}

/**
* @param \PhpParser\Node\ComplexType|\PhpParser\Node\Identifier|\PhpParser\Node\Name|NullableType|UnionType|IntersectionType|null $type Type declaration
*/
protected function typeToArray($type): array

Check failure on line 171 in src/Parser/NodeVisitor.php

View workflow job for this annotation

GitHub Actions / analyse-php

Method Doctum\Parser\NodeVisitor::typeToArray() return type has no value type specified in iterable type array.
{
$typeArray = [];
if ($type !== null && ! ($type instanceof NullableType || $type instanceof UnionType || $type instanceof IntersectionType)) {
$typeAsStr = $type->__toString();

Check failure on line 175 in src/Parser/NodeVisitor.php

View workflow job for this annotation

GitHub Actions / analyse-php

Ignored error pattern #^Call to an undefined method PhpParser\\Node\\ComplexType\|PhpParser\\Node\\Identifier\|PhpParser\\Node\\Name\:\:__toString\(\)\.$# (method.notFound) in path /home/runner/work/doctum/doctum/src/Parser/NodeVisitor.php is expected to occur 1 time, but occurred 2 times.
if ($type instanceof FullyQualified && 0 !== strpos($typeAsStr, '\\')) {
$typeAsStr = '\\' . $typeAsStr;
}
$typeArray[] = [$typeAsStr, false];
} elseif ($type instanceof NullableType) {
$typeArray = array_merge($typeArray, $this->typeToArray($type->type));
$typeArray[] = ['null', false];
} elseif ($type instanceof UnionType || $type instanceof IntersectionType) {
foreach ($type->types as $subType) {
$typeArray = array_merge($typeArray, $this->typeToArray($subType));
}
}

return $typeArray;
}

/**
* @param \PhpParser\Node\ComplexType|\PhpParser\Node\Identifier|\PhpParser\Node\Name|NullableType|UnionType|IntersectionType|null $type Type declaration
*/
Expand All @@ -172,7 +196,7 @@
{
$typeString = null;
if ($type !== null && ! ($type instanceof NullableType || $type instanceof UnionType || $type instanceof IntersectionType)) {
$typeString = $type->__toString();

Check failure on line 199 in src/Parser/NodeVisitor.php

View workflow job for this annotation

GitHub Actions / analyse-php

Call to an undefined method PhpParser\Node\ComplexType|PhpParser\Node\Identifier|PhpParser\Node\Name::__toString().
} elseif ($type instanceof NullableType) {
$typeString = $type->type->__toString();
} elseif ($type instanceof UnionType) {
Expand Down Expand Up @@ -439,20 +463,14 @@

$typeArr = [];
foreach ($type->types as $type) {
$typeStr = $this->typeToString($type);
$typeArr[] = [$typeStr, false];
$typeArr = array_merge($typeArr, $this->typeToArray($type));
}

$object->setHint($this->resolveHint($typeArr));
} else {
$typeStr = $this->typeToString($type);

if (null !== $typeStr) {
$typeArr = [[$typeStr, false]];
$typeArr = $this->typeToArray($type);

if ($type instanceof NullableType) {
$typeArr[] = ['null', false];
}
if (!empty($typeArr)) {
$object->setHint($this->resolveHint($typeArr));
}
}
Expand Down
Loading