Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;

/**
* @method static \Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\NormalParamClass disable(string|array ...$classes)
*/
class ImportMethodWithFirstParamUnion
{
}

?>
-----
<?php

namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;

use Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\NormalParamClass;

/**
* @method static NormalParamClass disable(string|array ...$classes)
*/
class ImportMethodWithFirstParamUnion
{
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public function enterNode(Node $node): ?Node
private function isWrappedInCurlyBrackets(BetterTokenIterator $betterTokenProvider, StartAndEnd $startAndEnd): bool
{
$previousPosition = $startAndEnd->getStart() - 1;
$nextPosition = $startAndEnd->getEnd() + 1;

if ($betterTokenProvider->isTokenTypeOnPosition(Lexer::TOKEN_OPEN_PARENTHESES, $previousPosition)) {
return true;
}

// there is no + 1, as end is right at the next token
return $betterTokenProvider->isTokenTypeOnPosition(Lexer::TOKEN_CLOSE_PARENTHESES, $startAndEnd->getEnd());
// A union is wrapped only when BOTH parens flank it. Either alone may be unrelated —
// e.g. an `@method`'s parameter-list `(` before a first-position union, or the matching
// `)` after a last-position union — neither belongs to the union type itself.
return $betterTokenProvider->isTokenTypeOnPosition(Lexer::TOKEN_OPEN_PARENTHESES, $previousPosition)
&& $betterTokenProvider->isTokenTypeOnPosition(Lexer::TOKEN_CLOSE_PARENTHESES, $nextPosition);
}

private function resolveStartAndEnd(UnionTypeNode $unionTypeNode): ?StartAndEnd
Expand Down
Loading