Skip to content

Commit 066432a

Browse files
authored
Merge pull request #287 from oliverklee/feature/php-cs-fixer
Add PHP CS Fixer to the toolchain
2 parents 59c23ac + 068624d commit 066432a

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ jobs:
9090
fail-fast: false
9191
matrix:
9292
include:
93-
- command: sniff
93+
- command: sniffer
9494
tool: phpcs
9595
php-version: 7.4
96+
- command: fixer
97+
tool: php-cs-fixer
98+
php-version: 7.4
9699
- command: stan
97100
tool: phpstan
98101
php-version: 7.4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.phive/*
2+
/.php-cs-fixer.cache
23
/.php_cs.cache
34
/composer.lock
45
/phpstan.neon

.phive/phars.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3+
<phar name="php-cs-fixer" version="^3.0.0" installed="3.0.0" location="./.phive/php-cs-fixer.phar" copy="false"/>
34
<phar name="phpcbf" version="^3.6.0" location="./.phive/phpcbf.phar" copy="false" installed="3.6.0"/>
45
<phar name="phpcs" version="^3.6.0" location="./.phive/phpcs.phar" copy="false" installed="3.6.0"/>
56
<phar name="phpstan" version="^0.12.88" installed="0.12.88" location="./.phive/phpstan.phar" copy="false"/>

composer.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,31 @@
3535
"ci": [
3636
"@ci:static"
3737
],
38-
"ci:php:sniff": "@php ./.phive/phpcs.phar --standard=config/phpcs.xml bin src tests",
38+
"ci:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix --dry-run -v --show-progress=dots bin src tests",
39+
"ci:php:sniffer": "@php ./.phive/phpcs.phar --standard=config/phpcs.xml bin src tests",
3940
"ci:php:stan": "@php ./.phive/phpstan.phar --configuration=config/phpstan.neon",
4041
"ci:static": [
41-
"@ci:php:sniff",
42+
"@ci:php:fixer",
43+
"@ci:php:sniffer",
4244
"@ci:php:stan"
4345
],
4446
"fix:php": [
45-
"@fix:php:sniff"
47+
"@fix:php:fixer",
48+
"@fix:php:sniffer"
4649
],
47-
"fix:php:sniff": "@php ./.phive/phpcbf.phar --standard=config/phpcs.xml bin src tests",
50+
"fix:php:fixer": "@php ./.phive/php-cs-fixer.phar --config=config/php-cs-fixer.php fix bin src tests",
51+
"fix:php:sniffer": "@php ./.phive/phpcbf.phar --standard=config/phpcs.xml bin src tests",
4852
"phpstan:baseline": "@php ./.phive/phpstan.phar --configuration=config/phpstan.neon --generate-baseline=config/phpstan-baseline.neon"
4953
},
5054
"scripts-descriptions": {
5155
"ci": "Runs all dynamic and static code checks (i.e. currently, only the static checks).",
52-
"ci:php:sniff": "Checks the code style with PHP_CodeSniffer.",
56+
"ci:php:fixer": "Checks the code style with PHP CS Fixer.",
57+
"ci:php:sniffer": "Checks the code style with PHP_CodeSniffer.",
5358
"ci:php:stan": "Checks the types with PHPStan.",
5459
"ci:static": "Runs all static code analysis checks for the code.",
5560
"fix:php": "Autofixes all autofixable issues in the PHP code.",
56-
"fix:php:sniff": "Fixes autofixable issues found by PHP_CodeSniffer.",
61+
"fix:php:fixer": "Fixes autofixable issues found by PHP CS Fixer.",
62+
"fix:php:sniffer": "Fixes autofixable issues found by PHP_CodeSniffer.",
5763
"phpstand:baseline": "Updates the PHPStan baseline file to match the code."
5864
}
5965
}

config/php-cs-fixer.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
if (PHP_SAPI !== 'cli') {
4+
die('This script supports command line usage only. Please check your command.');
5+
}
6+
7+
return (new \PhpCsFixer\Config())
8+
->setRiskyAllowed(true)
9+
->setRules(
10+
[
11+
'@PSR12' => true,
12+
// Disable constant visibility from the PSR12 rule set as this would break compatibility with PHP < 7.1.
13+
'visibility_required' => ['elements' => ['property', 'method']],
14+
]
15+
);

0 commit comments

Comments
 (0)