Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting standard, outfile and format to phpcs task #1612

Merged
merged 4 commits into from
Jun 16, 2021
Merged
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
9 changes: 9 additions & 0 deletions etc/phing-grammar.rng
Original file line number Diff line number Diff line change
Expand Up @@ -5314,6 +5314,15 @@
</choice>
</attribute>
</optional>
<optional>
<attribute name="standard"/>
</optional>
<optional>
<attribute name="format"/>
</optional>
<optional>
<attribute name="outfile"/>
</optional>
</interleave>
<zeroOrMore>
<ref name="fileset"/>
Expand Down
37 changes: 37 additions & 0 deletions src/Phing/Task/Optional/PhpCSTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions tests/Phing/Task/Optional/PhpCSTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
15 changes: 15 additions & 0 deletions tests/etc/tasks/ext/phpcs/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@
<fileset dir="../.." includes="**/*.php"/>
</phpcs>
</target>
<target name="testFileSetInPhpCs1FormatSet">
<phpcs bin="../../../../../bin/phpcs" format="checkstyle" level="debug" checkreturn="false" ignoreAnnotations="true" >
<fileset dir="../.." includes="**/*.php"/>
</phpcs>
</target>
<target name="testFileSetInPhpCs1StandardSet">
<phpcs bin="../../../../../bin/phpcs" standard="PSR12" level="debug" checkreturn="false" ignoreAnnotations="true" >
<fileset dir="../.." includes="**/*.php"/>
</phpcs>
</target>
<target name="testFileSetInPhpCs1OutfileSet">
<phpcs bin="../../../../../bin/phpcs" outfile="/dev/null" level="debug" checkreturn="false" ignoreAnnotations="true" >
<fileset dir="../.." includes="**/*.php"/>
</phpcs>
</target>
</project>