Skip to content

Commit

Permalink
Fix parent converting of union type based on token position (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Nov 1, 2021
1 parent 222f44f commit 99dfbea
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function enterNode(Node $node): ?Node
return null;
}

// unwrap with parent array type...
$startAndEnd = $node->getAttribute(PhpDocAttributeKey::START_AND_END);
$startAndEnd = $this->resolveStardAndEnd($node);
if (! $startAndEnd instanceof StartAndEnd) {
return null;
}
Expand All @@ -61,4 +60,20 @@ private function isWrappedInCurlyBrackets(BetterTokenIterator $betterTokenProvid
// there is no + 1, as end is right at the next token
return $betterTokenProvider->isTokenTypeOnPosition(Lexer::TOKEN_CLOSE_PARENTHESES, $startAndEnd->getEnd());
}

private function resolveStardAndEnd(Node $node): ?StartAndEnd
{
$starAndEnd = $node->getAttribute(PhpDocAttributeKey::START_AND_END);
if ($starAndEnd instanceof StartAndEnd) {
return $starAndEnd;
}

// unwrap with parent array type...
$parent = $node->getAttribute(PhpDocAttributeKey::PARENT);
if (! $parent instanceof Node) {
return null;
}

return $parent->getAttribute(PhpDocAttributeKey::START_AND_END);
}
}

0 comments on commit 99dfbea

Please sign in to comment.