Skip to content

Commit a6fb482

Browse files
committed
php-cs-fixer - allow custom .php_cs configuration instead of mapping rules in .phpqa.yml
1 parent 4939437 commit a6fb482

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

.phpqa.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ php-cs-fixer:
1818
allowRiskyRules: false
1919
# by default the tool is runned in dry-run mode (no fixers are applied)
2020
isDryRun: true
21+
# alternatively you can define path to your .phpcs_file (rules/allowRiskyRules config is ignored)
22+
config: null
2123

2224
phpmd:
2325
standard: app/phpmd.xml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Tool | Settings | Default Value | Your value
203203
[phpcs.reports](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting) | Report types | [`full`](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting#printing-full-and-summary-reports) report in [cli mode](#output-modes), [`checkstyle`](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting#printing-a-checkstyle-report) in [file mode](#output-modes) | Predefined [report types](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting) or [custom reports](https://github.com/wikidi/codesniffer#examples)
204204
[php-cs-fixer.rules](http://cs.sensiolabs.org/#usage) | Coding standard rules | `@PSR2` | String value
205205
[php-cs-fixer.allowRiskyRules](http://cs.sensiolabs.org/#usage) | Whether risky rules may run | `false` | Boolean value
206+
[php-cs-fixer.config](http://cs.sensiolabs.org/#usage) | Load configuration from [file](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/.php_cs.dist) | `null` | Path to `.phpcs` file
206207
[php-cs-fixer.isDryRun](http://cs.sensiolabs.org/#usage) | If code is just analyzed or fixers are applied | `true` | Boolean value
207208
[phpmd](http://phpmd.org/documentation/creating-a-ruleset.html) | Ruleset | [Edgedesign's standard](/app/phpmd.xml) | Path to ruleset
208209
[phpcpd](https://github.com/sebastianbergmann/phpcpd/blob/de9056615da6c1230f3294384055fa7d722c38fa/src/CLI/Command.php#L136) | Minimum number of lines/tokens for copy-paste detection | 5 lines, 70 tokens |

src/CodeAnalysisTasks.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,18 @@ private function phpcsfixer()
402402
$args = [
403403
'fix',
404404
$analyzedDir,
405-
'rules' => $this->config->value('php-cs-fixer.rules'),
406405
'verbose' => '',
407406
'format' => $this->options->isSavedToFiles ? 'junit' : 'txt',
408-
'allow-risky' => $this->config->value('php-cs-fixer.allowRiskyRules') ? 'yes' : 'no',
409407
];
408+
$configFile = $this->config->value('php-cs-fixer.config');
409+
if ($configFile) {
410+
$args['config'] = $configFile;
411+
} else {
412+
$args += [
413+
'rules' => $this->config->value('php-cs-fixer.rules'),
414+
'allow-risky' => $this->config->value('php-cs-fixer.allowRiskyRules') ? 'yes' : 'no',
415+
];
416+
}
410417
if ($this->config->value('php-cs-fixer.isDryRun')) {
411418
$args['dry-run'] = '';
412419
}

tests/Config/ConfigTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function testLoadDefaultConfig()
1616
assertThat($config->value('php-cs-fixer.rules'), is(nonEmptyString()));
1717
assertThat($config->value('php-cs-fixer.isDryRun'), identicalTo(true));
1818
assertThat($config->value('php-cs-fixer.allowRiskyRules'), identicalTo(false));
19+
assertThat($config->path('php-cs-fixer.config'), is(nullValue()));
1920
assertThat($config->path('phpmd.standard'), is(nonEmptyString()));
2021
assertThat($config->value('phpstan.level'), identicalTo(0));
2122
}

0 commit comments

Comments
 (0)