Skip to content

Commit a8170ea

Browse files
committed
Add CS fixer CI check
1 parent a9c6878 commit a8170ea

8 files changed

+208
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ phpunit.xml
22
composer.lock
33
vendor
44
bin
5+
.php_cs.cache

.php_cs

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__.'/src')
5+
->in(__DIR__.'/tests')
6+
;
7+
8+
return PhpCsFixer\Config::create()
9+
->setFinder($finder)
10+
->setRiskyAllowed(true)
11+
->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers())
12+
->setRules([
13+
'@PHP71Migration' => true,
14+
'@PSR1' => true,
15+
'@PSR2' => true,
16+
'array_indentation' => true,
17+
'array_syntax' => [ 'syntax' => 'short' ],
18+
'align_multiline_comment' => [
19+
'comment_type' => 'all_multiline',
20+
],
21+
'array_syntax' => [
22+
'syntax' => 'short',
23+
],
24+
'binary_operator_spaces' => true,
25+
'blank_line_after_opening_tag' => true,
26+
'blank_line_before_statement' => true,
27+
'cast_spaces' => true,
28+
'class_attributes_separation' => true,
29+
'combine_consecutive_issets' => true,
30+
'combine_consecutive_unsets' => true,
31+
'compact_nullable_typehint' => true,
32+
'concat_space' => ['spacing' => 'one'],
33+
'date_time_immutable' => true,
34+
'declare_equal_normalize' => [
35+
'space' => 'single',
36+
],
37+
'dir_constant' => true,
38+
'ereg_to_preg' => true,
39+
'escape_implicit_backslashes' => true,
40+
'explicit_indirect_variable' => true,
41+
'explicit_string_variable' => true,
42+
'fopen_flag_order' => true,
43+
'fopen_flags' => true,
44+
'fully_qualified_strict_types' => true,
45+
'function_to_constant' => [
46+
'functions' => [
47+
'get_class',
48+
'php_sapi_name',
49+
'phpversion',
50+
'pi',
51+
]
52+
],
53+
'function_typehint_space' => true,
54+
'global_namespace_import' => true,
55+
'heredoc_to_nowdoc' => true,
56+
'implode_call' => true,
57+
'include' => true,
58+
'is_null' => true,
59+
'linebreak_after_opening_tag' => true,
60+
'list_syntax' => [
61+
'syntax' => 'long',
62+
],
63+
'logical_operators' => true,
64+
'lowercase_cast' => true,
65+
'lowercase_static_reference' => true,
66+
'magic_constant_casing' => true,
67+
'magic_method_casing' => true,
68+
'method_chaining_indentation' => true,
69+
'modernize_types_casting' => true,
70+
'multiline_comment_opening_closing' => true,
71+
'multiline_whitespace_before_semicolons' => [
72+
'strategy' => 'new_line_for_chained_calls',
73+
],
74+
'native_constant_invocation' => [
75+
'include' => ['@internal'],
76+
'scope' => 'all',
77+
],
78+
'native_function_casing' => true,
79+
'native_function_invocation' => true,
80+
'native_function_type_declaration_casing' => true,
81+
'new_with_braces' => true,
82+
'no_alternative_syntax' => true,
83+
'no_binary_string' => true,
84+
'no_blank_lines_after_class_opening' => true,
85+
'no_blank_lines_after_phpdoc' => true,
86+
'no_empty_comment' => true,
87+
'no_empty_phpdoc' => true,
88+
'no_empty_statement' => true,
89+
'no_extra_blank_lines' => [
90+
'tokens' => ['extra']
91+
],
92+
'no_leading_import_slash' => true,
93+
'no_leading_namespace_whitespace' => true,
94+
'no_mixed_echo_print' => true,
95+
'no_multiline_whitespace_around_double_arrow' => true,
96+
'no_short_bool_cast' => true,
97+
'no_short_echo_tag' => true,
98+
'no_singleline_whitespace_before_semicolons' => true,
99+
'no_spaces_around_offset' => [
100+
'positions' => ['inside', 'outside'],
101+
],
102+
'no_superfluous_elseif' => true,
103+
'no_superfluous_phpdoc_tags' => false,
104+
'no_trailing_comma_in_list_call' => true,
105+
'no_trailing_comma_in_singleline_array' => true,
106+
'no_unneeded_curly_braces' => true,
107+
'no_unused_imports' => true,
108+
'no_useless_else' => true,
109+
'no_useless_return' => true,
110+
'no_whitespace_before_comma_in_array' => true,
111+
'no_whitespace_in_blank_line' => true,
112+
'normalize_index_brace' => true,
113+
'object_operator_without_whitespace' => true,
114+
'ordered_class_elements' => [
115+
'order' => [
116+
'use_trait',
117+
'constant_public',
118+
'constant_protected',
119+
'constant_private',
120+
'property_public',
121+
'property_protected',
122+
'property_private',
123+
'construct',
124+
'destruct',
125+
'magic',
126+
'phpunit',
127+
'method_public',
128+
'method_protected',
129+
'method_private'
130+
],
131+
],
132+
'php_unit_construct' => [
133+
'assertions' => [
134+
'assertEquals',
135+
'assertSame',
136+
'assertNotEquals',
137+
'assertNotSame'
138+
]
139+
],
140+
// Check on other phpunit stuff
141+
'phpdoc_align' => [
142+
'align' => 'vertical'
143+
],
144+
'phpdoc_indent' => true,
145+
'phpdoc_inline_tag' => true,
146+
'phpdoc_no_access' => true,
147+
'phpdoc_no_alias_tag' => true,
148+
'phpdoc_no_empty_return' => false,
149+
'phpdoc_no_package' => true,
150+
'phpdoc_no_useless_inheritdoc' => true,
151+
'phpdoc_order' => true,
152+
'phpdoc_return_self_reference' => true,
153+
'phpdoc_scalar' => true,
154+
'phpdoc_separation' => true,
155+
'phpdoc_single_line_var_spacing' => true,
156+
'phpdoc_summary' => true,
157+
'phpdoc_to_comment' => true,
158+
'phpdoc_trim' => true,
159+
'phpdoc_trim_consecutive_blank_line_separation' => true,
160+
'phpdoc_types' => true,
161+
'phpdoc_types_order' => true,
162+
'phpdoc_var_annotation_correct_order' => true,
163+
'phpdoc_var_without_name' => true,
164+
'psr4' => true,
165+
'return_assignment' => true,
166+
'return_type_declaration' => true,
167+
'semicolon_after_instruction' => true,
168+
'short_scalar_cast' => true,
169+
'single_blank_line_before_namespace' => true,
170+
'single_line_comment_style' => true,
171+
'single_line_throw' => true,
172+
'single_quote' => true,
173+
'single_trait_insert_per_statement' => true,
174+
'space_after_semicolon' => true,
175+
'standardize_increment' => true,
176+
'standardize_not_equals' => true,
177+
'strict_comparison' => true,
178+
'ternary_operator_spaces' => true,
179+
'trailing_comma_in_multiline_array' => true,
180+
'trim_array_spaces' => true,
181+
'unary_operator_spaces' => true,
182+
'whitespace_after_comma_in_array' => true,
183+
'PedroTroller/exceptions_punctuation' => true,
184+
'PedroTroller/line_break_between_method_arguments' => [
185+
'max-args' => 5,
186+
],
187+
'PedroTroller/useless_code_after_return' => true,
188+
])
189+
;

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ install: composer update --prefer-dist
3232
script:
3333
- vendor/bin/phpunit
3434
- vendor/bin/phpstan analyse --ansi --no-progress
35+
- vendor/bin/php-cs-fixer fix --diff --dry-run --no-progress --verbose

composer.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"require-dev": {
2424
"phpunit/phpunit": "~7.4",
2525
"phpstan/phpstan": "^0.12.7",
26-
"phpstan/phpstan-phpunit": "^0.12.6"
26+
"phpstan/phpstan-phpunit": "^0.12.6",
27+
"friendsofphp/php-cs-fixer": "^2.16",
28+
"pedrotroller/php-cs-custom-fixer": "^2.19"
2729
},
2830
"suggest": {
2931
"h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency",
@@ -44,7 +46,9 @@
4446
},
4547
"scripts": {
4648
"unit-tests": "vendor/bin/phpunit",
47-
"static-analysis": "vendor/bin/phpstan analyse --ansi"
49+
"static-analysis": "vendor/bin/phpstan analyse --ansi",
50+
"check-cs": "vendor/bin/php-cs-fixer fix --diff --dry-run --verbose",
51+
"fix-cs": "vendor/bin/php-cs-fixer fix --verbose"
4852
},
4953
"extra": {
5054
"branch-alias": {

src/Knp/Snappy/AbstractGenerator.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public function setLogger(LoggerInterface $logger): self
9696
/**
9797
* This method must configure the media options.
9898
*
99+
* @return void
100+
*
99101
* @see AbstractGenerator::addOption()
100102
*/
101103
abstract protected function configure(): void;
@@ -551,7 +553,7 @@ protected function isAssociativeArray(array $array): bool
551553
*
552554
* @param string $command
553555
*
554-
* @return array(status, stdout, stderr)
556+
* @return array [status, stdout, stderr]
555557
*/
556558
protected function executeCommand(string $command): array
557559
{

src/Knp/Snappy/GeneratorInterface.php

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ interface GeneratorInterface
1818
* @param string $output The output media filename
1919
* @param array $options An array of options for this generation only
2020
* @param bool $overwrite Overwrite the file if it exists. If not, throw a FileAlreadyExistsException
21+
*
22+
* @return void
2123
*/
2224
public function generate($input, string $output, array $options = [], bool $overwrite = false): void;
2325

@@ -28,6 +30,8 @@ public function generate($input, string $output, array $options = [], bool $over
2830
* @param string $output The output media filename
2931
* @param array $options An array of options for this generation only
3032
* @param bool $overwrite Overwrite the file if it exists. If not, throw a FileAlreadyExistsException
33+
*
34+
* @return void
3135
*/
3236
public function generateFromHtml($html, string $output, array $options = [], bool $overwrite = false): void;
3337

tests/Knp/Snappy/AbstractGeneratorTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ public function testBuildCommand(string $binary, string $url, string $path, arra
556556
$this->assertEquals($expected, $r->invokeArgs($media, [$binary, $url, $path, $options]));
557557
}
558558

559+
/**
560+
* @return string|null
561+
*/
559562
private function getPHPExecutableFromPath(): ?string
560563
{
561564
if (isset($_SERVER['_'])) {

tests/Knp/Snappy/PdfTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testThatSomethingUsingNonexistentTmpFolder(): void
6262
$testObject = new PdfSpy();
6363
$testObject->setTemporaryFolder($temporaryFolder);
6464

65-
$output = $testObject->getOutputFromHtml('<html></html>', ['footer-html' => 'footer']);
65+
$testObject->getOutputFromHtml('<html></html>', ['footer-html' => 'footer']);
6666

6767
$this->assertDirectoryExists($temporaryFolder);
6868
}

0 commit comments

Comments
 (0)