Skip to content

Commit

Permalink
Merge pull request #42 from hhashimoto/fix-fully-qualified-name
Browse files Browse the repository at this point in the history
fix parsing class bug
  • Loading branch information
gossi authored Mar 30, 2017
2 parents 841e810 + 1458547 commit 6f10f1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parser/visitor/ClassParserVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ public function visitClass(Class_ $node) {
$struct = $this->getStruct();

if ($node->extends !== null) {
$struct->setParentClassName(implode('\\', $node->extends->parts));
if ($node->extends->getType() === 'Name_FullyQualified') {
$struct->setParentClassName('\\' . implode('\\', $node->extends->parts));
} else {
$struct->setParentClassName(implode('\\', $node->extends->parts));
}
}

foreach ($node->implements as $name) {
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/MyCollection2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
class MyCollection2 extends \phootwork\collection\AbstractCollection implements \phootwork\collection\Collection {

}
7 changes: 7 additions & 0 deletions tests/parser/ClassParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public function testMyCollection() {
$this->assertEquals('phootwork\collection\AbstractCollection', $class->getParentClassName());
$this->assertTrue($class->hasInterface('phootwork\collection\Collection'));
}

public function testMyCollection2() {
$class = PhpClass::fromFile(__DIR__ . '/../fixtures/MyCollection2.php');

$this->assertEquals('\phootwork\collection\AbstractCollection', $class->getParentClassName());
$this->assertTrue($class->hasInterface('\phootwork\collection\Collection'));
}

public function testTypeClass() {
$class = PhpClass::fromFile(__DIR__ . '/../fixtures/TypeClass.php');
Expand Down

0 comments on commit 6f10f1e

Please sign in to comment.