Skip to content

Commit

Permalink
Merge pull request #285 from Dionera/triggered_by-option-for-phpcsfix…
Browse files Browse the repository at this point in the history
…er2-task

Triggered by option for phpcsfixer2 task
  • Loading branch information
veewee authored Feb 10, 2017
2 parents e4d4862 + f0b4576 commit c26b6f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions doc/tasks/php_cs_fixer2.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ parameters:
path_mode: ~
verbose: true
diff: false
triggered_by: ['php']
```
Expand Down Expand Up @@ -84,3 +85,11 @@ Show applied fixers.
*Default: false*

Show the full diff that will be applied.


**triggered_by**

*Default: [php]*

This option will specify which file extensions will trigger the phpcsfixer2 task.

1 change: 1 addition & 0 deletions spec/Task/PhpCsFixerV2Spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function it_should_have_configurable_options()
$options->getDefinedOptions()->shouldContain('path_mode');
$options->getDefinedOptions()->shouldContain('verbose');
$options->getDefinedOptions()->shouldContain('diff');
$options->getDefinedOptions()->shouldContain('triggered_by');
}

function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context)
Expand Down
6 changes: 4 additions & 2 deletions src/Task/PhpCsFixerV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function getConfigurableOptions()
'path_mode' => null,
'verbose' => true,
'diff' => false,
'triggered_by' => ['php'],
]);

$resolver->addAllowedTypes('allow_risky', ['bool']);
Expand All @@ -45,6 +46,7 @@ public function getConfigurableOptions()
$resolver->addAllowedTypes('path_mode', ['null', 'string']);
$resolver->addAllowedTypes('verbose', ['bool']);
$resolver->addAllowedTypes('diff', ['bool']);
$resolver->addAllowedTypes('triggered_by', ['array']);

$resolver->setAllowedValues('path_mode', [null, 'override', 'intersection']);

Expand All @@ -56,12 +58,12 @@ public function getConfigurableOptions()
*/
public function run(ContextInterface $context)
{
$files = $context->getFiles()->name('*.php');
$config = $this->getConfiguration();
$files = $context->getFiles()->extensions($config['triggered_by']);
if (0 === count($files)) {
return TaskResult::createSkipped($this, $context);
}

$config = $this->getConfiguration();
$this->formatter->resetCounter();

$arguments = $this->processBuilder->createArgumentsForCommand('php-cs-fixer');
Expand Down

0 comments on commit c26b6f9

Please sign in to comment.