Skip to content

Commit 010f46b

Browse files
committedJan 11, 2022
PHP-CS fixer setup for maintaining coding styles and standard
1 parent c8b88d5 commit 010f46b

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed
 

‎.gitattributes

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
/.github export-ignore
99
/tests export-ignore
10-
.editorconfig export-ignore
11-
.gitattributes export-ignore
12-
.gitignore export-ignore
13-
phpunit.xml export-ignore
10+
/.editorconfig export-ignore
11+
/.gitattributes export-ignore
12+
/.gitignore export-ignore
13+
/phpunit.xml export-ignore
14+
/.php_cs.dist.php export-ignore

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.composer
44
composer.lock
55
package-lock.json
6+
.php-cs-fixer.cache
67
vendor/
78
test/
89

‎.php_cs.dist.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in([
5+
__DIR__ . '/src',
6+
__DIR__ . '/tests',
7+
])
8+
->name('*.php')
9+
->ignoreDotFiles(true)
10+
->ignoreVCS(true);
11+
12+
return (new PhpCsFixer\Config())
13+
->setRules([
14+
'@PSR12' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
17+
'no_unused_imports' => true,
18+
'not_operator_with_successor_space' => true,
19+
'trailing_comma_in_multiline' => true,
20+
'phpdoc_scalar' => true,
21+
'unary_operator_spaces' => true,
22+
'binary_operator_spaces' => true,
23+
'blank_line_before_statement' => [
24+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
25+
],
26+
'phpdoc_single_line_var_spacing' => true,
27+
'phpdoc_var_without_name' => true,
28+
'method_argument_space' => [
29+
'on_multiline' => 'ensure_fully_multiline',
30+
'keep_multiple_spaces_after_comma' => true,
31+
],
32+
'single_trait_insert_per_statement' => true,
33+
])
34+
->setFinder($finder);

‎composer.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"leafs/anchor": "^1.1"
3737
},
3838
"require-dev": {
39-
"pestphp/pest": "^1.21"
40-
}
41-
}
39+
"pestphp/pest": "^1.21",
40+
"friendsofphp/php-cs-fixer": "^3.0"
41+
},
42+
"scripts": {
43+
"format": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist.php --allow-risky=yes"
44+
}
45+
}

0 commit comments

Comments
 (0)