diff --git a/lib/PhpParser/BuilderAbstract.php b/lib/PhpParser/BuilderAbstract.php index d615756..c804686 100644 --- a/lib/PhpParser/BuilderAbstract.php +++ b/lib/PhpParser/BuilderAbstract.php @@ -48,9 +48,9 @@ abstract class BuilderAbstract implements Builder { } else { return new Name($name); } - } else { - return new Name($name); } + + throw new \LogicException('Name must be a string or an instance of PhpParser\Node\Name'); } /** diff --git a/test/PhpParser/Builder/ClassTest.php b/test/PhpParser/Builder/ClassTest.php index ec9d138..f4c181f 100644 --- a/test/PhpParser/Builder/ClassTest.php +++ b/test/PhpParser/Builder/ClassTest.php @@ -145,8 +145,17 @@ DOC; * @expectedException \LogicException * @expectedExceptionMessage Name cannot be empty */ - public function testInvalidName() { + public function testEmptyName() { $this->createClassBuilder('Test') ->extend(''); } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage Name must be a string or an instance of PhpParser\Node\Name + */ + public function testInvalidName() { + $this->createClassBuilder('Test') + ->extend(['Foo']); + } }