Skip to content

Commit

Permalink
[PSR4] Fix test on NormalizeNamespaceByPSR4ComposerAutoloadRector (#1063
Browse files Browse the repository at this point in the history
)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Oct 26, 2021
1 parent 877cf17 commit 87a6907
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,37 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($this->inlineHTMLAnalyzer->hasInlineHTML($node)) {
$processNode = clone $node;
if ($this->inlineHTMLAnalyzer->hasInlineHTML($processNode)) {
return null;
}

$expectedNamespace = $this->psr4AutoloadNamespaceMatcher->getExpectedNamespace($this->file, $node);
$expectedNamespace = $this->psr4AutoloadNamespaceMatcher->getExpectedNamespace($this->file, $processNode);
if ($expectedNamespace === null) {
return null;
}

// is namespace and already correctly named?
if ($node instanceof Namespace_ && $this->nodeNameResolver->isCaseSensitiveName($node, $expectedNamespace)) {
if ($processNode instanceof Namespace_ && $this->nodeNameResolver->isCaseSensitiveName(
$processNode,
$expectedNamespace
)) {
return null;
}

if ($node instanceof Namespace_ && $this->hasNamespaceInPreviousNamespace($node)) {
if ($processNode instanceof Namespace_ && $this->hasNamespaceInPreviousNamespace($processNode)) {
return null;
}

// to put declare_strict types on correct place
if ($node instanceof FileWithoutNamespace) {
return $this->refactorFileWithoutNamespace($node, $expectedNamespace);
if ($processNode instanceof FileWithoutNamespace) {
return $this->refactorFileWithoutNamespace($processNode, $expectedNamespace);
}

$node->name = new Name($expectedNamespace);
$this->fullyQualifyStmtsAnalyzer->process($node->stmts);
$processNode->name = new Name($expectedNamespace);
$this->fullyQualifyStmtsAnalyzer->process($processNode->stmts);

return $node;
return $processNode;
}

private function hasNamespaceInPreviousNamespace(Namespace_ $namespace): bool
Expand Down

0 comments on commit 87a6907

Please sign in to comment.