From b232c9f1659206ed4136b3274239e65d04c8ebb0 Mon Sep 17 00:00:00 2001 From: Aleh Kashnikau Date: Sun, 14 Aug 2016 14:35:40 +0300 Subject: [PATCH] fixed parsing of semantically wrong classes --- features/semantic-class-errors.feature | 32 +++++++++++++++++++ src/Padawan/Domain/Project/Node/ClassData.php | 7 ++-- .../Domain/Project/InMemoryIndex.php | 14 ++++++++ .../Parser/Exception/SemanticError.php | 13 ++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 features/semantic-class-errors.feature create mode 100644 src/Padawan/Parser/Exception/SemanticError.php 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 @@ +