Skip to content

Commit a51afca

Browse files
authored
Merge pull request #21 from Cheppers/i20-multi-standards
Issue #20 - Comma separated standards
2 parents ac4adfb + 11a3eed commit a51afca

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

RoboFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ protected function getTaskPhpcsLint()
254254

255255
$options = [
256256
'failOn' => 'warning',
257-
'standard' => 'PSR2',
257+
'standards' => ['PSR2'],
258258
'lintReporters' => [
259259
'lintVerboseReporter' => null,
260260
],

src/Task/PhpcsLint.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ abstract class PhpcsLint extends BaseTask implements
9797
];
9898

9999
protected $simpleOptions = [
100-
'standard' => 'standard',
101100
'reportWidth' => 'report-width',
102101
'severity' => 'severity',
103102
'errorSeverity' => 'error-severity',
@@ -107,6 +106,7 @@ abstract class PhpcsLint extends BaseTask implements
107106
protected $listOptions = [
108107
'extensions' => 'extensions',
109108
'sniffs' => 'sniffs',
109+
'standards' => 'standard',
110110
'exclude' => 'exclude',
111111
'ignored' => 'ignore',
112112
];
@@ -282,8 +282,8 @@ public function setOptions(array $options)
282282
$this->setWarningSeverity($value);
283283
break;
284284

285-
case 'standard':
286-
$this->setStandard($value);
285+
case 'standards':
286+
$this->setStandards($value);
287287
break;
288288

289289
case 'extensions':
@@ -497,23 +497,25 @@ public function setWarningSeverity(?int $value)
497497

498498
//region Option - standard
499499
/**
500-
* @var string
500+
* @var bool[]
501501
*/
502-
protected $standard = '';
502+
protected $standards = [];
503503

504-
public function getStandard(): string
504+
public function getStandards(): array
505505
{
506-
return $this->standard;
506+
return $this->standards;
507507
}
508508

509509
/**
510510
* Set the name or path of the coding standard to use.
511511
*
512512
* @return $this
513513
*/
514-
public function setStandard(string $name)
514+
public function setStandards(array $standards)
515515
{
516-
$this->standard = $name;
516+
$this->standards = gettype(reset($standards)) === 'boolean' ?
517+
$standards
518+
: array_fill_keys($standards, true);
517519

518520
return $this;
519521
}
@@ -736,7 +738,7 @@ protected function getCommandOptions(): array
736738
{
737739
$options = [
738740
'colors' => $this->getColors(),
739-
'standard' => $this->getStandard(),
741+
'standards' => $this->getStandards(),
740742
'reports' => $this->getReports(),
741743
'reportWidth' => $this->getReportWidth(),
742744
'severity' => $this->getSeverity(),
@@ -1027,7 +1029,7 @@ protected function getTaskContext($context = null)
10271029
return [
10281030
'name' => 'PHP_CodeSniffer',
10291031
'command' => $this->getCommand(),
1030-
'standard' => $this->getStandard(),
1032+
'standard' => implode(',', $this->filterEnabled($this->getStandards())),
10311033
] + parent::getTaskContext($context);
10321034
}
10331035
}

tests/_data/RoboFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function lintFilesAllInOne()
4545

4646
return $this->taskPhpcsLintFiles()
4747
->setColors(false)
48-
->setStandard('PSR2')
48+
->setStandards(['PSR2'])
4949
->setFiles(['fixtures/psr2.invalid.01.php'])
5050
->setReport('full')
5151
->setReport('checkstyle', "$reportsDir/01.native.checkstyle.xml")
@@ -97,7 +97,7 @@ public function lintInputWithoutJar(
9797
}
9898

9999
return $this->taskPhpcsLintInput()
100-
->setStandard('PSR2')
100+
->setStandards(['PSR2'])
101101
->setFiles($files)
102102
->addLintReporter('verbose:StdOutput', 'lintVerboseReporter')
103103
->addLintReporter('verbose:file', $verboseFile)

tests/unit/Task/PhpcsLintFilesTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,17 @@ public function casesGetCommand(): array
184184
"phpcs --error-severity='0'",
185185
['errorSeverity' => '0'],
186186
],
187-
'standard-false' => [
187+
'standards-empty' => [
188188
'phpcs',
189-
['standard' => false],
189+
['standards' => []],
190190
],
191-
'standard-value' => [
192-
"phpcs --standard='Drupal'",
193-
['standard' => 'Drupal'],
191+
'standards-vector' => [
192+
"phpcs --standard='a,b'",
193+
['standards' => ['a', 'b', 'a']],
194+
],
195+
'standards-boolean' => [
196+
"phpcs --standard='a,c'",
197+
['standards' => ['a' => true, 'b' => false, 'c' => true]],
194198
],
195199
'extensions-empty' => [
196200
"phpcs",

0 commit comments

Comments
 (0)