From 11a3eed4367c64a9c34679b00d301acffe33a1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andor=20D=C3=A1vid?= Date: Thu, 15 Jun 2017 21:46:01 +0200 Subject: [PATCH] Issue #20 - Comma separated standards --- RoboFile.php | 2 +- src/Task/PhpcsLint.php | 24 +++++++++++++----------- tests/_data/RoboFile.php | 4 ++-- tests/unit/Task/PhpcsLintFilesTest.php | 14 +++++++++----- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 681694c..bca7026 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -254,7 +254,7 @@ protected function getTaskPhpcsLint() $options = [ 'failOn' => 'warning', - 'standard' => 'PSR2', + 'standards' => ['PSR2'], 'lintReporters' => [ 'lintVerboseReporter' => null, ], diff --git a/src/Task/PhpcsLint.php b/src/Task/PhpcsLint.php index 16b6da3..db03676 100644 --- a/src/Task/PhpcsLint.php +++ b/src/Task/PhpcsLint.php @@ -97,7 +97,6 @@ abstract class PhpcsLint extends BaseTask implements ]; protected $simpleOptions = [ - 'standard' => 'standard', 'reportWidth' => 'report-width', 'severity' => 'severity', 'errorSeverity' => 'error-severity', @@ -107,6 +106,7 @@ abstract class PhpcsLint extends BaseTask implements protected $listOptions = [ 'extensions' => 'extensions', 'sniffs' => 'sniffs', + 'standards' => 'standard', 'exclude' => 'exclude', 'ignored' => 'ignore', ]; @@ -282,8 +282,8 @@ public function setOptions(array $options) $this->setWarningSeverity($value); break; - case 'standard': - $this->setStandard($value); + case 'standards': + $this->setStandards($value); break; case 'extensions': @@ -497,13 +497,13 @@ public function setWarningSeverity(?int $value) //region Option - standard /** - * @var string + * @var bool[] */ - protected $standard = ''; + protected $standards = []; - public function getStandard(): string + public function getStandards(): array { - return $this->standard; + return $this->standards; } /** @@ -511,9 +511,11 @@ public function getStandard(): string * * @return $this */ - public function setStandard(string $name) + public function setStandards(array $standards) { - $this->standard = $name; + $this->standards = gettype(reset($standards)) === 'boolean' ? + $standards + : array_fill_keys($standards, true); return $this; } @@ -736,7 +738,7 @@ protected function getCommandOptions(): array { $options = [ 'colors' => $this->getColors(), - 'standard' => $this->getStandard(), + 'standards' => $this->getStandards(), 'reports' => $this->getReports(), 'reportWidth' => $this->getReportWidth(), 'severity' => $this->getSeverity(), @@ -1027,7 +1029,7 @@ protected function getTaskContext($context = null) return [ 'name' => 'PHP_CodeSniffer', 'command' => $this->getCommand(), - 'standard' => $this->getStandard(), + 'standard' => implode(',', $this->filterEnabled($this->getStandards())), ] + parent::getTaskContext($context); } } diff --git a/tests/_data/RoboFile.php b/tests/_data/RoboFile.php index a63afb9..bb1cf6f 100644 --- a/tests/_data/RoboFile.php +++ b/tests/_data/RoboFile.php @@ -45,7 +45,7 @@ public function lintFilesAllInOne() return $this->taskPhpcsLintFiles() ->setColors(false) - ->setStandard('PSR2') + ->setStandards(['PSR2']) ->setFiles(['fixtures/psr2.invalid.01.php']) ->setReport('full') ->setReport('checkstyle', "$reportsDir/01.native.checkstyle.xml") @@ -97,7 +97,7 @@ public function lintInputWithoutJar( } return $this->taskPhpcsLintInput() - ->setStandard('PSR2') + ->setStandards(['PSR2']) ->setFiles($files) ->addLintReporter('verbose:StdOutput', 'lintVerboseReporter') ->addLintReporter('verbose:file', $verboseFile) diff --git a/tests/unit/Task/PhpcsLintFilesTest.php b/tests/unit/Task/PhpcsLintFilesTest.php index b714df5..2ead908 100644 --- a/tests/unit/Task/PhpcsLintFilesTest.php +++ b/tests/unit/Task/PhpcsLintFilesTest.php @@ -184,13 +184,17 @@ public function casesGetCommand(): array "phpcs --error-severity='0'", ['errorSeverity' => '0'], ], - 'standard-false' => [ + 'standards-empty' => [ 'phpcs', - ['standard' => false], + ['standards' => []], ], - 'standard-value' => [ - "phpcs --standard='Drupal'", - ['standard' => 'Drupal'], + 'standards-vector' => [ + "phpcs --standard='a,b'", + ['standards' => ['a', 'b', 'a']], + ], + 'standards-boolean' => [ + "phpcs --standard='a,c'", + ['standards' => ['a' => true, 'b' => false, 'c' => true]], ], 'extensions-empty' => [ "phpcs",