Skip to content

Commit 2ae1a4a

Browse files
padraictheofidry
authored andcommitted
Properly scope fully-qualified class name nodes (#56)
Properly scope fully-qualified class name nodes and fix unrelated bug stripping \ from start of FQN Closes #53
1 parent 24b428b commit 2ae1a4a

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/NodeVisitor/FullyQualifiedNamespaceUseScoperNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function enterNode(Node $node)
4040
&& false === ($node->hasAttribute('phpscoper_ignore')
4141
&& true === $node->getAttribute('phpscoper_ignore'))
4242
) {
43-
return new Name(Name::concat($this->prefix, (string) $node));
43+
return new Name('\\'.Name::concat($this->prefix, (string) $node));
4444
}
4545

4646
return $node;

src/NodeVisitor/IgnoreNamespaceScoperNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function enterNode(Node $node)
2828
{
2929
if ($node instanceof FullyQualified
3030
&& $node->isFullyQualified()
31-
&& 1 === count($node->getSubNodeNames())
31+
&& 1 === count($node->parts)
3232
) {
3333
$node->setAttribute('phpscoper_ignore', true);
3434
}

tests/Scoper/PhpScoperTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,28 @@ public function provideValidFiles()
590590
591591
use const Humbug\FooNamespace\FOO;
592592

593+
PHP
594+
];
595+
596+
//
597+
// FQN usage for a name
598+
//
599+
// ====================
600+
601+
yield '[FQN usage for a name] fully qualified class' => [
602+
<<<'PHP'
603+
<?php
604+
605+
new \Foo\Bar();
606+
607+
PHP
608+
,
609+
'Humbug',
610+
<<<'PHP'
611+
<?php
612+
613+
new \Humbug\Foo\Bar();
614+
593615
PHP
594616
];
595617

0 commit comments

Comments
 (0)