From 950b4519d8f69077aaf4c2a074c58c861144a253 Mon Sep 17 00:00:00 2001 From: Arne Blankerts Date: Wed, 10 Jan 2018 00:13:47 +0100 Subject: [PATCH] Fix #242 --- src/Application.php | 7 ++++++ src/collector/InheritanceResolver.php | 34 ++++++++++++++++++++++++++- tests/data/issue242/src/test.php | 5 ++++ tests/data/issue242/test.xml | 15 ++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/data/issue242/src/test.php create mode 100644 tests/data/issue242/test.xml diff --git a/src/Application.php b/src/Application.php index ea48da9e..d15529a9 100644 --- a/src/Application.php +++ b/src/Application.php @@ -153,6 +153,13 @@ public function runCollector(CollectorConfig $config) { $this->logger->log(' - ' . $class . ' (missing ' . $missing . ')'); } } + + if ($resolver->hasErrors()) { + $this->logger->log('The following unit(s) caused errors during inheritance resolution:'); + foreach($resolver->getErrors() as $class => $error) { + $this->logger->log(' - ' . $class . ': ' . implode(', ', $error)); + } + } } $this->logger->log("Collector process completed\n"); } diff --git a/src/collector/InheritanceResolver.php b/src/collector/InheritanceResolver.php index d855ffc8..39655f95 100644 --- a/src/collector/InheritanceResolver.php +++ b/src/collector/InheritanceResolver.php @@ -37,8 +37,8 @@ namespace TheSeer\phpDox\Collector { use TheSeer\fDOM\fDOMDocument; - use TheSeer\phpDox\ProgressLogger; use TheSeer\phpDox\InheritanceConfig; + use TheSeer\phpDox\ProgressLogger; /** * Inheritance resolving class @@ -67,6 +67,11 @@ class InheritanceResolver { */ private $unresolved = array(); + /** + * @var array + */ + private $errors = array(); + /** * @param ProgressLogger $logger */ @@ -153,6 +158,22 @@ public function getUnresolved() { return $this->unresolved; } + public function hasErrors() { + return count($this->errors) > 0; + } + + public function getErrors() { + return $this->errors; + } + + private function addError(AbstractUnitObject $unit, $errorInfo) { + $unitName = $unit->getName(); + if (!isset($this->errors[$unitName])) { + $this->errors[$unitName] = array(); + } + $this->errors[$unitName][] = $errorInfo; + } + private function addUnresolved(AbstractUnitObject $unit, $missingUnit) { $unitName = $unit->getName(); if (!isset($this->unresolved[$unitName])) { @@ -212,6 +233,17 @@ private function processImplements(AbstractUnitObject $unit, AbstractUnitObject $this->project->registerForSaving($unit); $this->project->registerForSaving($implements); + if (!$implements instanceof InterfaceObject) { + $this->addError( + $unit, + sprintf( + 'Trying to implement "%s" which is a %s', + $implements->getName(), + $implements->getType() + ) + ); + return; + } $implements->addImplementor($unit); $unit->importExports($implements, 'interface'); diff --git a/tests/data/issue242/src/test.php b/tests/data/issue242/src/test.php new file mode 100644 index 00000000..e6d7f037 --- /dev/null +++ b/tests/data/issue242/src/test.php @@ -0,0 +1,5 @@ + + + + + + + + + + + + + + +