diff --git a/classes/phing/tasks/ext/phploc/PHPLocFormatterFactory.php b/classes/phing/tasks/ext/phploc/PHPLocFormatterFactory.php index 9a19e1e456..66251cfb11 100644 --- a/classes/phing/tasks/ext/phploc/PHPLocFormatterFactory.php +++ b/classes/phing/tasks/ext/phploc/PHPLocFormatterFactory.php @@ -39,16 +39,16 @@ public static function createFormatter($formatterElement) switch ($type) { case "xml": - include_once 'phing/tasks/ext/phploc/PHPLocXMLFormatter.php'; $formatter = new PHPLocXMLFormatter(); break; + case "json": + $formatter = new PHPLocJSONFormatter(); + break; case "csv": - include_once 'phing/tasks/ext/phploc/PHPLocCSVFormatter.php'; $formatter = new PHPLocCSVFormatter(); break; case "txt": case "cli": - include_once 'phing/tasks/ext/phploc/PHPLocTextFormatter.php'; $formatter = new PHPLocTextFormatter(); break; default: diff --git a/classes/phing/tasks/ext/phploc/PHPLocJSONFormatter.php b/classes/phing/tasks/ext/phploc/PHPLocJSONFormatter.php new file mode 100644 index 0000000000..b15b4d91c1 --- /dev/null +++ b/classes/phing/tasks/ext/phploc/PHPLocJSONFormatter.php @@ -0,0 +1,35 @@ +. + */ + +/** + * @author Siad Ardroumli + * @package phing.tasks.ext.phploc + */ +class PHPLocJSONFormatter extends AbstractPHPLocFormatter +{ + public function printResult(array $count, $countTests = false) + { + if (class_exists('\\SebastianBergmann\\PHPLOC\\Log\\Json')) { + $printer = new SebastianBergmann\PHPLOC\Log\Json(); + } else { + throw new BuildException('Not supported PHPLOC version used.'); + } + $printer->printResult($this->getToDir() . DIRECTORY_SEPARATOR . $this->getOutfile(), $count); + } +} diff --git a/classes/phing/tasks/ext/phploc/PHPLocTask.php b/classes/phing/tasks/ext/phploc/PHPLocTask.php index 7cbd2e8c78..a8350adef5 100644 --- a/classes/phing/tasks/ext/phploc/PHPLocTask.php +++ b/classes/phing/tasks/ext/phploc/PHPLocTask.php @@ -35,7 +35,7 @@ class PHPLocTask extends Task /** * @var array */ - protected $acceptedReportTypes = ['cli', 'txt', 'xml', 'csv']; + protected $acceptedReportTypes = ['cli', 'txt', 'xml', 'csv', 'json']; /** * @var null @@ -302,10 +302,10 @@ protected function getFilesToCheck() if (count($this->filesToCheck) > 0) { foreach ($this->filesToCheck as $file) { - $files[] = new SplFileInfo($file); + $files[] = (new SplFileInfo($file))->getRealPath(); } } elseif ($this->fileToCheck !== null) { - $files = [new SplFileInfo($this->fileToCheck)]; + $files = [(new SplFileInfo($this->fileToCheck))->getRealPath()]; } return $files; diff --git a/classes/phing/tasks/ext/phploc/PHPLocTextFormatter.php b/classes/phing/tasks/ext/phploc/PHPLocTextFormatter.php index 13c2acbe71..2aba7bdc6a 100644 --- a/classes/phing/tasks/ext/phploc/PHPLocTextFormatter.php +++ b/classes/phing/tasks/ext/phploc/PHPLocTextFormatter.php @@ -25,17 +25,15 @@ class PHPLocTextFormatter extends AbstractPHPLocFormatter { public function printResult(array $count, $countTests = false) { + $printerClass = '\\SebastianBergmann\\PHPLOC\\Log\\Text'; + $printer = new $printerClass(); if ($this->getUseFile()) { - $outputClass = '\\Symfony\\Component\\Console\\Output\\StreamOutput'; - $stream = fopen($this->getToDir() . DIRECTORY_SEPARATOR . $this->getOutfile(), 'a+'); - $output = new $outputClass($stream); + ob_start(); + $printer->printResult($count, $countTests); + $output = ob_get_clean(); + file_put_contents($this->getToDir() . DIRECTORY_SEPARATOR . $this->getOutfile(), $output, FILE_APPEND); } else { - $outputClass = '\\Symfony\\Component\\Console\\Output\\ConsoleOutput'; - $output = new $outputClass(); + $printer->printResult($count, $countTests); } - - $printerClass = '\\SebastianBergmann\\PHPLOC\\Log\\Text'; - $printer = new $printerClass(); - $printer->printResult($output, $count, $countTests); } } diff --git a/classes/phing/tasks/ext/phploc/PHPLocXMLFormatter.php b/classes/phing/tasks/ext/phploc/PHPLocXMLFormatter.php index eb1e633beb..8ebc1415c6 100644 --- a/classes/phing/tasks/ext/phploc/PHPLocXMLFormatter.php +++ b/classes/phing/tasks/ext/phploc/PHPLocXMLFormatter.php @@ -25,9 +25,7 @@ class PHPLocXMLFormatter extends AbstractPHPLocFormatter { public function printResult(array $count, $countTests = false) { - if (class_exists('\\SebastianBergmann\\PHPLOC\\Log\\XML')) { - $printer = new SebastianBergmann\PHPLOC\Log\XML(); - } elseif (class_exists('\\SebastianBergmann\\PHPLOC\\Log\\Xml')) { + if (class_exists('\\SebastianBergmann\\PHPLOC\\Log\\Xml')) { $printer = new SebastianBergmann\PHPLOC\Log\Xml(); } else { throw new BuildException('Not supported PHPLOC version used.'); diff --git a/test/classes/phing/tasks/ext/PHPLOCTaskTest.php b/test/classes/phing/tasks/ext/PHPLOCTaskTest.php index 7778d5fbaa..ea565cd139 100644 --- a/test/classes/phing/tasks/ext/PHPLOCTaskTest.php +++ b/test/classes/phing/tasks/ext/PHPLOCTaskTest.php @@ -22,8 +22,6 @@ * * @author Michiel Rook * @package phing.tasks.ext - * - * @requires PHP < 7.3 */ class PHPLOCTaskTest extends BuildFileTest { @@ -59,6 +57,15 @@ public function testReportXML() unlink(PHING_TEST_BASE . '/etc/tasks/ext/phploc/phploc-report.xml'); } + public function testReportJSON() + { + $this->executeTarget(__FUNCTION__); + $this->assertFileExists( + PHING_TEST_BASE . '/etc/tasks/ext/phploc/phploc-report.json' + ); + unlink(PHING_TEST_BASE . '/etc/tasks/ext/phploc/phploc-report.json'); + } + public function testFormatters() { $this->executeTarget(__FUNCTION__); diff --git a/test/etc/tasks/ext/phploc/build.xml b/test/etc/tasks/ext/phploc/build.xml index 0e7903c841..84c8a1087a 100644 --- a/test/etc/tasks/ext/phploc/build.xml +++ b/test/etc/tasks/ext/phploc/build.xml @@ -26,11 +26,21 @@ + + + + + + + + +