Skip to content

Commit

Permalink
Fix #242
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Jan 9, 2018
1 parent d4bdbcd commit 950b451
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
34 changes: 33 additions & 1 deletion src/collector/InheritanceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,6 +67,11 @@ class InheritanceResolver {
*/
private $unresolved = array();

/**
* @var array
*/
private $errors = array();

/**
* @param ProgressLogger $logger
*/
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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');

Expand Down
5 changes: 5 additions & 0 deletions tests/data/issue242/src/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class test { }

class foo implements test {}
15 changes: 15 additions & 0 deletions tests/data/issue242/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpdox xmlns="http://xml.phpdox.net/config" silent="false">

<project name="phpDox-issue" source="${basedir}/src" workdir="${basedir}/xml">

<collector publiconly="false" backend="parser" />

<generator output="${basedir}/docs">
<build engine="html" enabled="true" output="html" />
<build engine="xml" enabled="true" output="xml" />
</generator>

</project>

</phpdox>

0 comments on commit 950b451

Please sign in to comment.