diff --git a/etc/phing-grammar.rng b/etc/phing-grammar.rng index 910641a8e9..7c9b959f1e 100644 --- a/etc/phing-grammar.rng +++ b/etc/phing-grammar.rng @@ -5314,6 +5314,15 @@ + + + + + + + + + diff --git a/src/Phing/Task/Optional/PhpCSTask.php b/src/Phing/Task/Optional/PhpCSTask.php index 333838d9a2..45fcf36c14 100644 --- a/src/Phing/Task/Optional/PhpCSTask.php +++ b/src/Phing/Task/Optional/PhpCSTask.php @@ -21,6 +21,7 @@ namespace Phing\Task\Optional; use Phing\Exception\BuildException; +use Phing\Project; use Phing\Io\File; use Phing\Task; use Phing\Task\System\Element\LogLevelAware; @@ -64,6 +65,15 @@ class PhpCSTask extends Task /** @var bool */ private $checkreturn = false; + /** @var string */ + private $standard = ''; + + /** @var string */ + private $outfile = ''; + + /** @var string */ + private $format = ''; + /** @var string */ private $bin = 'phpcs'; @@ -99,11 +109,29 @@ public function setBin(string $bin): void $this->bin = $bin; } + public function setFormat(string $format): void + { + $this->format = $format; + $this->project->log("Format set to $format", Project::MSG_VERBOSE); + } + + public function setStandard(string $standard): void + { + $this->standard = $standard; + $this->project->log("Standard set to $standard", Project::MSG_VERBOSE); + } + public function setFile(File $file): void { $this->file = $file; } + public function setOutfile(string $outfile): void + { + $this->outfile = $outfile; + $this->project->log("Outfile set to $outfile", Project::MSG_VERBOSE); + } + public function main() { if (null === $this->file && 0 == count($this->filesets)) { @@ -128,6 +156,15 @@ public function main() if ($this->ignoreAnnotations) { $toExecute->createArgument()->setValue('--ignore-annotations'); } + if ($this->format !== '') { + $toExecute->createArgument()->setValue(' --report=' . $this->format); + } + if ($this->standard !== '') { + $toExecute->createArgument()->setValue(' --standard=' . $this->standard); + } + if ($this->outfile !== '') { + $toExecute->createArgument()->setValue(' --report-file=' . $this->outfile); + } if (null !== $this->file) { $toExecute->createArgument()->setFile($this->file); diff --git a/tests/Phing/Task/Optional/PhpCSTaskTest.php b/tests/Phing/Task/Optional/PhpCSTaskTest.php index e3164d0cb6..6e5efc5ad7 100644 --- a/tests/Phing/Task/Optional/PhpCSTaskTest.php +++ b/tests/Phing/Task/Optional/PhpCSTaskTest.php @@ -55,4 +55,16 @@ public function testFileSetInPhpCs1(): void $this->expectNotToPerformAssertions(); $this->executeTarget(__FUNCTION__); } + + public function testFileSetInPhpCs1OutfileSet(): void + { + $this->executeTarget(__FUNCTION__); + $this->assertInLogs('Outfile set to /dev/null'); + } + + public function testFileSetInPhpCs1FormatSet(): void + { + $this->executeTarget(__FUNCTION__); + $this->assertInLogs('Format set to checkstyle'); + } } diff --git a/tests/etc/tasks/ext/phpcs/build.xml b/tests/etc/tasks/ext/phpcs/build.xml index db5a1cef4a..26d274df99 100644 --- a/tests/etc/tasks/ext/phpcs/build.xml +++ b/tests/etc/tasks/ext/phpcs/build.xml @@ -12,4 +12,19 @@ + + + + + + + + + + + + + + +