Skip to content

Commit

Permalink
share more code with checkstyle enricher
Browse files Browse the repository at this point in the history
  • Loading branch information
Reno Reckling committed Jul 31, 2014
1 parent 578a141 commit 79195a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 52 deletions.
22 changes: 12 additions & 10 deletions src/generator/enricher/checkstyle/CheckStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,21 @@ private function processFindings(fDOMDocument $dom, \DOMNodeList $findings) {
// but we have individual objects - so we just ignore the finding for this context
continue;
}
$this->processFinding($dom, $ref, $finding);
}

$enrichment = $this->getEnrichtmentContainer($ref, 'checkstyle');
$enrichFinding = $dom->createElementNS(self::XMLNS, $finding->getAttribute('severity', 'error'));
$enrichment->appendChild($enrichFinding);
foreach($finding->attributes as $attr) {
if ($attr->localName == 'severity') {
continue;
}
$enrichFinding->setAttributeNode($dom->importNode($attr, true));
}
}

protected function processFinding(fDOMDocument $dom, $ref, \DOMElement $finding) {
$enrichment = $this->getEnrichtmentContainer($ref, 'checkstyle');
$enrichFinding = $dom->createElementNS(self::XMLNS, $finding->getAttribute('severity', 'error'));
$enrichment->appendChild($enrichFinding);
foreach($finding->attributes as $attr) {
if ($attr->localName == 'severity') {
continue;
}
$enrichFinding->setAttributeNode($dom->importNode($attr, true));
}

}
}

Expand Down
52 changes: 10 additions & 42 deletions src/generator/enricher/phpcs/PHPCs.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use TheSeer\phpDox\Generator\InterfaceStartEvent;
use TheSeer\phpDox\Generator\TraitStartEvent;

class PHPCs extends AbstractEnricher implements ClassEnricherInterface, TraitEnricherInterface, InterfaceEnricherInterface {
class PHPCs extends CheckStyle {

private $config;
private $findings = NULL;
Expand All @@ -28,25 +28,6 @@ public function getName() {
return 'PHPCS XML';
}

public function enrichClass(ClassStartEvent $event) {
$this->enrichUnit($event->getClass());
}

public function enrichInterface(InterfaceStartEvent $event) {
$this->enrichUnit($event->getInterface());
}

public function enrichTrait(TraitStartEvent $event) {
$this->enrichUnit($event->getTrait());
}

private function enrichUnit(AbstractUnitObject $ctx) {
$file = $ctx->getSourceFile();
if (isset($this->findings[$file])) {
$this->processFindings($ctx->asDom(), $this->findings[$file]);
}
}

private function loadFindings($xmlFile) {
$this->findings = array();
try {
Expand All @@ -69,31 +50,18 @@ private function loadFindings($xmlFile) {
}
}

private function processFindings(fDOMDocument $dom, \DOMNodeList $findings) {

foreach($findings as $finding) {
/** @var fDOMElement $finding */
$line = $finding->getAttribute('line');
$ref = $dom->queryOne(sprintf('//phpdox:*/*[@line = %d or (@start <= %d and @end >= %d)]', $line, $line, $line));
if (!$ref) {
// One src file may contain multiple classes/traits/interfaces, so the
// finding might not apply to the current object since findings are based on filenames
// but we have individual objects - so we just ignore the finding for this context
protected function processFinding(fDOMDocument $dom, $ref, \DOMElement $finding)
{
$enrichment = $this->getEnrichtmentContainer($ref, 'checkstyle');
$enrichFinding = $dom->createElementNS(self::XMLNS, $finding->tagName);
$enrichment->appendChild($enrichFinding);
foreach($finding->attributes as $attr) {
if ($attr->localName == 'severity') {
continue;
}

$enrichment = $this->getEnrichtmentContainer($ref, 'checkstyle');
$enrichFinding = $dom->createElementNS(self::XMLNS, $finding->tagName);
$enrichment->appendChild($enrichFinding);
foreach($finding->attributes as $attr) {
if ($attr->localName == 'severity') {
continue;
}
$enrichFinding->setAttributeNode($dom->importNode($attr, true));
}
$enrichFinding->setAttribute('message', $finding->nodeValue);
$enrichFinding->setAttributeNode($dom->importNode($attr, true));
}

$enrichFinding->setAttribute('message', $finding->nodeValue);
}
}

Expand Down

0 comments on commit 79195a5

Please sign in to comment.