Skip to content

Commit 390e722

Browse files
author
Feyyaz Esatoglu
authored
Merge pull request #2 from mollie/APM-541
PHP-Cs-Fixer config centralized.
2 parents 6ff8cd4 + 6e60289 commit 390e722

File tree

5 files changed

+214
-2
lines changed

5 files changed

+214
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.php_cs.cache

.php_cs.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
6+
$finder = Finder::create()
7+
->name('.php_cs.dist') // Fix this file as well
8+
->in(__DIR__);
9+
10+
return Config::create()
11+
->setFinder($finder)
12+
->setRiskyAllowed(true)
13+
->setRules(Rules::getForPhp71());

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# coding-standards
2-
Contains coding standards like rules for Php-cs-fixer, github hooks that serves for purpose of standardisation.
1+
# Mollie PHP Coding Standards
2+
3+
Contains PHP coding standards like rules for PHP-CS-Fixer that serves for purpose of standardization.

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "mollie/php-coding-standards",
3+
"description": "Contains PHP coding standards like rules for PHP-CS-Fixer that serves for purpose of standardization.",
4+
"license": "proprietary",
5+
"type": "library",
6+
"authors": [
7+
{
8+
"name": "Mollie B.V.",
9+
"email": "info@mollie.com"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"Mollie\\PhpCodingStandards\\": "src/"
15+
}
16+
},
17+
"minimum-stability": "stable",
18+
"require": {
19+
"php": "^7.1.3"
20+
},
21+
"require-dev": {
22+
"friendsofphp/php-cs-fixer": "^2.15"
23+
},
24+
"bin": [
25+
"bin/link-git-hooks"
26+
]
27+
}

src/PhpCsFixer/Rules.php

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Mollie\PhpCodingStandards\PhpCsFixer;
6+
7+
/*
8+
* Last updated for php-cs-fixer version: 2.15
9+
*/
10+
class Rules
11+
{
12+
public static function getForPhp71(array $overriddenRules = []): array
13+
{
14+
return array_merge(self::getBaseRules(), $overriddenRules);
15+
}
16+
17+
public static function getForPhp72(array $overriddenRules = []) : array
18+
{
19+
$specific72Rules = [
20+
// At the moment there are no specific 7.2 rules or configurations
21+
];
22+
23+
return array_merge(self::getForPhp71($specific72Rules), $overriddenRules);
24+
}
25+
26+
public static function getForPhp73(array $overriddenRules = []) : array
27+
{
28+
$specific73Rules = [
29+
'heredoc_indentation' => true,
30+
'method_argument_space' => [
31+
'after_heredoc' => true,
32+
'on_multiline' => 'ensure_fully_multiline',
33+
],
34+
'no_whitespace_before_comma_in_array' => [
35+
'after_heredoc' => true,
36+
],
37+
];
38+
39+
return array_merge(self::getForPhp72($specific73Rules), $overriddenRules);
40+
}
41+
42+
private static function getBaseRules(): array
43+
{
44+
return [
45+
'@Symfony' => true,
46+
'align_multiline_comment' => [
47+
'comment_type' => 'all_multiline',
48+
],
49+
'array_indentation' => true,
50+
'array_syntax' => [
51+
'syntax' => 'short',
52+
],
53+
'binary_operator_spaces' => [
54+
'default' => 'align_single_space_minimal',
55+
],
56+
'blank_line_before_statement' => [
57+
'statements' => [
58+
'break', 'continue', 'case', 'declare', 'default', 'do', 'for', 'foreach',
59+
'if', 'return', 'switch', 'throw', 'try', 'while', 'yield',
60+
],
61+
],
62+
'cast_spaces' => [
63+
'space' => 'none',
64+
],
65+
'combine_consecutive_issets' => true,
66+
'combine_consecutive_unsets' => true,
67+
'combine_nested_dirname' => true,
68+
'compact_nullable_typehint' => true,
69+
'concat_space' => [
70+
'spacing' => 'one',
71+
],
72+
'dir_constant' => true,
73+
'escape_implicit_backslashes' => true,
74+
'explicit_indirect_variable' => true,
75+
'explicit_string_variable' => true,
76+
'fully_qualified_strict_types' => true,
77+
'function_to_constant' => true,
78+
// 'header_comment' => [ // Has too many issues atm
79+
// 'header' => '',
80+
// ],
81+
'increment_style' => [
82+
'style' => 'post',
83+
],
84+
'is_null' => [
85+
'use_yoda_style' => false,
86+
],
87+
'list_syntax' => [
88+
'syntax' => 'short',
89+
],
90+
'magic_method_casing' => true,
91+
'method_argument_space' => [
92+
'on_multiline' => 'ensure_fully_multiline',
93+
],
94+
'method_chaining_indentation' => true,
95+
'modernize_types_casting' => true,
96+
'multiline_comment_opening_closing' => true,
97+
'multiline_whitespace_before_semicolons' => true,
98+
'native_function_type_declaration_casing' => true,
99+
'no_alias_functions' => true,
100+
'no_alternative_syntax' => true,
101+
'no_extra_blank_lines' => [
102+
'tokens' => [
103+
'break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block',
104+
'return', 'square_brace_block', 'throw', 'use_trait',
105+
// TODO: Add 'use' when php-cs-fixer #3582 is fixed
106+
],
107+
],
108+
'no_null_property_initialization' => true,
109+
'no_superfluous_elseif' => true,
110+
'no_superfluous_phpdoc_tags' => true,
111+
'no_unset_cast' => true,
112+
'no_unset_on_property' => false, // It's purposely used for the side effect :(
113+
'no_useless_else' => true,
114+
'no_useless_return' => true,
115+
'ordered_class_elements' => [
116+
'order' => [
117+
'use_trait',
118+
'constant_public', 'constant_protected', 'constant_private',
119+
'property_public', 'property_protected', 'property_private',
120+
// Not shuffling methods. I'd love to do it but I think it's too much for most people.
121+
],
122+
],
123+
'ordered_imports' => [
124+
'imports_order' => ['class', 'function', 'const'],
125+
],
126+
'php_unit_construct' => true,
127+
'php_unit_dedicate_assert_internal_type' => true,
128+
'php_unit_method_casing' => true,
129+
'php_unit_test_case_static_method_calls' => [
130+
'call_type' => 'self',
131+
],
132+
'phpdoc_annotation_without_dot' => false, // Sometimes comments have a good reason to end with a dot. Leave this up to the engineer.
133+
'phpdoc_no_alias_tag' => [
134+
'replacements' => [
135+
'link' => 'see',
136+
'type' => 'var',
137+
],
138+
],
139+
'phpdoc_order' => true,
140+
'phpdoc_summary' => false, // Sometimes comments have a good reason not to end with a dot. Leave this up to the engineer.
141+
'phpdoc_to_comment' => false, // We use more annotations than only structural elements (f.e. @lang JSON)
142+
'phpdoc_trim_consecutive_blank_line_separation' => true,
143+
'phpdoc_types_order' => [
144+
'null_adjustment' => 'always_last',
145+
],
146+
'phpdoc_var_annotation_correct_order' => true,
147+
'pow_to_exponentiation' => true,
148+
'return_assignment' => true,
149+
'simple_to_complex_string_variable' => true,
150+
'simplified_null_return' => false, // Too many old code places that become implicit, also ignores doc blocks.
151+
'single_class_element_per_statement' => true,
152+
'single_quote' => false,
153+
'single_trait_insert_per_statement' => true,
154+
'space_after_semicolon' => [
155+
'remove_in_empty_for_expressions' => true,
156+
],
157+
'ternary_to_null_coalescing' => true,
158+
'visibility_required' => [
159+
'elements' => [
160+
'const', 'method', 'property',
161+
],
162+
],
163+
'yoda_style' => [
164+
'equal' => false,
165+
'identical' => false,
166+
'less_and_greater' => false,
167+
],
168+
];
169+
}
170+
}

0 commit comments

Comments
 (0)