diff --git a/features/semantic-class-errors.feature b/features/semantic-class-errors.feature new file mode 100644 index 0000000..a779f61 --- /dev/null +++ b/features/semantic-class-errors.feature @@ -0,0 +1,32 @@ +Feature: Semantic errors in classes + As a user + I want all semantic invalid classes to be excluded from index + So that I can have project with broken classes or deps + + Scenario: Class extending itself + Given there is a file with: + """ + parent = null; if ($parent instanceof ClassData) { diff --git a/src/Padawan/Framework/Domain/Project/InMemoryIndex.php b/src/Padawan/Framework/Domain/Project/InMemoryIndex.php index 2e1dd2c..8b1e019 100644 --- a/src/Padawan/Framework/Domain/Project/InMemoryIndex.php +++ b/src/Padawan/Framework/Domain/Project/InMemoryIndex.php @@ -181,6 +181,9 @@ public function getFunctions() } public function addClass(ClassData $class) { + if (!$this->isSemanticsCorrect($class)) { + return; + } $this->classes[$class->fqcn->toString()] = $class; if ($class->getParent() instanceof FQCN) { $this->addExtend($class, $class->getParent()); @@ -238,4 +241,15 @@ private function hasCoreIndex() { return $this !== self::$coreIndex && !empty(self::$coreIndex); } + + private function isSemanticsCorrect(ClassData $class) + { + if ($class->getParent() === $class) { + return false; + } + if ($class->getParent() instanceof FQCN + && $class->getParent()->toString() === $class->fqcn->toString()) { + return false; + } + } } diff --git a/src/Padawan/Parser/Exception/SemanticError.php b/src/Padawan/Parser/Exception/SemanticError.php new file mode 100644 index 0000000..8bcce95 --- /dev/null +++ b/src/Padawan/Parser/Exception/SemanticError.php @@ -0,0 +1,13 @@ +