Skip to content

Commit 917c418

Browse files
committed
➕ Add php-cs-fixer
1 parent dd65a34 commit 917c418

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/composer.lock
33
/vendor/
44
tests-report/
5-
/.idea/
5+
/.idea/
6+
.php_cs.cache

.php_cs.dist

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/**
4+
* @source https://gist.github.com/codfish/c77d348820c1c6b4ebe4a66dc2291c74
5+
*
6+
* Rules we follow are from PSR-2 as well as the rectified PSR-2 guide.
7+
*
8+
* - https://github.com/FriendsOfPHP/PHP-CS-Fixer
9+
* - https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
10+
* - https://github.com/php-fig-rectified/fig-rectified-standards/blob/master/PSR-2-R-coding-style-guide-additions.md
11+
*
12+
* If something isn't addressed in either of those, some other common community rules are
13+
* used that might not be addressed explicitly in PSR-2 in order to improve code quality
14+
* (so that devs don't need to comment on them in Code Reviews).
15+
*
16+
* For instance: removing trailing white space, removing extra line breaks where
17+
* they're not needed (back to back, beginning or end of function/class, etc.),
18+
* adding trailing commas in the last line of an array, etc.
19+
*/
20+
21+
$finder = PhpCsFixer\Finder::create()
22+
->exclude('node_modules')
23+
->exclude('vendor')
24+
->in(__DIR__);
25+
26+
return PhpCsFixer\Config::create()
27+
->setRules([
28+
'@PSR2' => true,
29+
'array_syntax' => [ 'syntax' => 'short' ],
30+
'binary_operator_spaces' => [ 'align_equals' => false, 'align_double_arrow' => false ],
31+
'cast_spaces' => true,
32+
'combine_consecutive_unsets' => true,
33+
'concat_space' => [ 'spacing' => 'one' ],
34+
'linebreak_after_opening_tag' => true,
35+
'no_blank_lines_after_class_opening' => true,
36+
'no_blank_lines_after_phpdoc' => true,
37+
'no_extra_consecutive_blank_lines' => true,
38+
'no_trailing_comma_in_singleline_array' => true,
39+
'no_whitespace_in_blank_line' => true,
40+
'no_spaces_around_offset' => true,
41+
'no_unused_imports' => true,
42+
'no_useless_else' => true,
43+
'no_useless_return' => true,
44+
'no_whitespace_before_comma_in_array' => true,
45+
'normalize_index_brace' => true,
46+
'phpdoc_indent' => true,
47+
'phpdoc_to_comment' => true,
48+
'phpdoc_trim' => true,
49+
'single_quote' => true,
50+
'ternary_to_null_coalescing' => true,
51+
'trailing_comma_in_multiline_array' => true,
52+
'trim_array_spaces' => true,
53+
'method_argument_space' => ['ensure_fully_multiline' => false],
54+
'no_break_comment' => false,
55+
'blank_line_before_statement' => true,
56+
])
57+
->setFinder($finder);

composer.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "~4.0",
20-
"phpunit/php-code-coverage": "~2.0"
20+
"phpunit/php-code-coverage": "~2.0",
21+
"friendsofphp/php-cs-fixer": "~2.14"
2122
},
2223
"autoload": {
2324
"psr-0": {"Bramus": "src/"}
2425
},
2526
"scripts": {
26-
"test": "./vendor/bin/phpunit --colors=always"
27+
"test": "./vendor/bin/phpunit --colors=always",
28+
"lint": "php-cs-fixer fix --diff --dry-run",
29+
"fix": "php-cs-fixer fix"
2730
}
2831
}

0 commit comments

Comments
 (0)