Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/Log/AbstractXmlLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ abstract class AbstractXmlLogger
{
protected $document;

protected $xml;

/**
* Constructor.
*
* @param string $filename
*/
public function __construct($filename)
public function __construct($filename = null)
{
$this->document = new \DOMDocument('1.0', 'UTF-8');
$this->document->formatOutput = TRUE;
Expand All @@ -72,11 +74,23 @@ public function __construct($filename)
}

/**
* Writes the XML document to the file.
* Writes the XML document to the file or catches document content
*/
protected function flush()
{
file_put_contents($this->filename, $this->document->saveXML());
if ($this->filename) {
file_put_contents($this->filename, $this->document->saveXML());
} else {
$this->xml = $this->document->saveXML();
}
}

/**
* Get XML content if no save file was given.
*/
public function getXML()
{
return $this->xml;
}

/**
Expand Down
33 changes: 29 additions & 4 deletions src/TextUI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public function main()
)
);

$input->registerOption(
new \ezcConsoleOption(
'',
'xml-out',
\ezcConsoleInput::TYPE_NONE,
NULL,
FALSE
)
);

$input->registerOption(
new \ezcConsoleOption(
'',
Expand Down Expand Up @@ -201,6 +211,7 @@ public function main()

$excludes = $input->getOption('exclude')->value;
$logPmd = $input->getOption('log-pmd')->value;
$xmlOut = $input->getOption('xml-out')->value;
$minLines = $input->getOption('min-lines')->value;
$minTokens = $input->getOption('min-tokens')->value;
$names = explode(',', $input->getOption('names')->value);
Expand All @@ -215,7 +226,9 @@ public function main()
$output = NULL;
}

$this->printVersionString();
if (!$xmlOut) {
$this->printVersionString();
}

$finder = new FinderFacade($arguments, $excludes, $names);
$files = $finder->findFiles();
Expand All @@ -231,16 +244,26 @@ public function main()
$files, $minLines, $minTokens
);

$printer = new ResultPrinter;
$printer->printResult($clones, !$quiet, $verbose);
unset($printer);
if (!$xmlOut) {
$printer = new ResultPrinter;
$printer->printResult($clones, !$quiet, $verbose);
unset($printer);
}

if ($logPmd) {
$pmd = new PMD($logPmd);
$pmd->processClones($clones);
unset($pmd);
}

if ($xmlOut) {
$pmdxml = new PMD();
$pmdxml->processClones($clones);
print $pmdxml->getXML();
unset($pmdxml);
exit(0);
}

if (count($clones) > 0) {
exit(1);
}
Expand Down Expand Up @@ -272,6 +295,8 @@ protected function showHelp()

--log-pmd <file> Write report in PMD-CPD XML format to file.

--xml-out Write report in PMD-CPD XML format to stdout.

--min-lines <N> Minimum number of identical lines (default: 5).
--min-tokens <N> Minimum number of identical tokens (default: 70).

Expand Down