diff --git a/tests/Model/BasePHPElement.php b/tests/Model/BasePHPElement.php index ef055281..e32cbee9 100644 --- a/tests/Model/BasePHPElement.php +++ b/tests/Model/BasePHPElement.php @@ -3,9 +3,6 @@ declare(strict_types=1); namespace StubTests\Model; -use PhpParser\Node\Stmt\Namespace_; -use PhpParser\NodeAbstract; - abstract class BasePHPElement { public $name; @@ -28,16 +25,6 @@ abstract class BasePHPElement abstract public function readMutedProblems($jsonData); - protected function getConstantFQN(NodeAbstract $node, string $nodeName): string - { - $namespace = ''; - if ($node->getAttribute('parent') instanceof Namespace_ && !empty($node->getAttribute('parent')->name)) { - $namespace = '\\' . implode('\\', $node->getAttribute('parent')->name->parts) . '\\'; - } - - return $namespace . $nodeName; - } - protected function getFQN($node): string { $fqn = ''; diff --git a/tests/Model/PHPConst.php b/tests/Model/PHPConst.php index baa00c78..5f9640ae 100644 --- a/tests/Model/PHPConst.php +++ b/tests/Model/PHPConst.php @@ -5,6 +5,8 @@ namespace StubTests\Model; use PhpParser\Node\Const_; use PhpParser\Node\Stmt\ClassConst; +use PhpParser\Node\Stmt\Namespace_; +use PhpParser\NodeAbstract; use ReflectionClassConstant; use stdClass; @@ -55,6 +57,17 @@ class PHPConst extends BasePHPElement return null; } + protected function getConstantFQN(NodeAbstract $node, string $nodeName): string + { + $namespace = ''; + $parentParentNode = $node->getAttribute('parent')->getAttribute('parent'); + if ($parentParentNode instanceof Namespace_ && !empty($parentParentNode->name)) { + $namespace = '\\' . implode('\\', $parentParentNode->name->parts) . '\\'; + } + + return $namespace . $nodeName; + } + public function readMutedProblems($jsonData): void { /**@var stdClass $constant */ diff --git a/tests/Model/StubsContainer.php b/tests/Model/StubsContainer.php index 5e6d68b0..ed9bc7ce 100644 --- a/tests/Model/StubsContainer.php +++ b/tests/Model/StubsContainer.php @@ -37,6 +37,9 @@ class StubsContainer */ public function addConstant(PHPConst $constant): void { + if (array_key_exists($constant->name, $this->constants)) { + throw new \Exception($constant->name . " is already defined in stubs"); + } $this->constants[$constant->name] = $constant; } @@ -82,6 +85,9 @@ class StubsContainer */ public function addClass(PHPClass $class): void { + if (array_key_exists($class->name, $this->classes)) { + throw new \Exception($class->name . " is already defined in stubs"); + } $this->classes[$class->name] = $class; } @@ -111,6 +117,9 @@ class StubsContainer */ public function addInterface(PHPInterface $interface): void { + if (array_key_exists($interface->name, $this->interfaces)) { + throw new \Exception($interface->name . " is already defined in stubs"); + } $this->interfaces[$interface->name] = $interface; } }