Skip to content

Commit

Permalink
Issue #20 - Comma separated standards
Browse files Browse the repository at this point in the history
  • Loading branch information
Andor Dávid committed Jun 15, 2017
1 parent ac4adfb commit 11a3eed
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function getTaskPhpcsLint()

$options = [
'failOn' => 'warning',
'standard' => 'PSR2',
'standards' => ['PSR2'],
'lintReporters' => [
'lintVerboseReporter' => null,
],
Expand Down
24 changes: 13 additions & 11 deletions src/Task/PhpcsLint.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ abstract class PhpcsLint extends BaseTask implements
];

protected $simpleOptions = [
'standard' => 'standard',
'reportWidth' => 'report-width',
'severity' => 'severity',
'errorSeverity' => 'error-severity',
Expand All @@ -107,6 +106,7 @@ abstract class PhpcsLint extends BaseTask implements
protected $listOptions = [
'extensions' => 'extensions',
'sniffs' => 'sniffs',
'standards' => 'standard',
'exclude' => 'exclude',
'ignored' => 'ignore',
];
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -497,23 +497,25 @@ 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;
}

/**
* Set the name or path of the coding standard to use.
*
* @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;
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions tests/_data/RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -97,7 +97,7 @@ public function lintInputWithoutJar(
}

return $this->taskPhpcsLintInput()
->setStandard('PSR2')
->setStandards(['PSR2'])
->setFiles($files)
->addLintReporter('verbose:StdOutput', 'lintVerboseReporter')
->addLintReporter('verbose:file', $verboseFile)
Expand Down
14 changes: 9 additions & 5 deletions tests/unit/Task/PhpcsLintFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 11a3eed

Please sign in to comment.