Skip to content

Commit 7c777af

Browse files
committed
Update PHP-CS-Fixer rules
1 parent 8166505 commit 7c777af

File tree

5 files changed

+87
-46
lines changed

5 files changed

+87
-46
lines changed

.php_cs.dist

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,27 @@ return PhpCsFixer\Config::create()
1010
->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer' . preg_replace('~\W~', '-', __DIR__))
1111
->setRules([
1212
'align_multiline_comment' => true,
13+
'array_indentation' => true,
1314
'array_syntax' => ['syntax' => 'short'],
1415
'backtick_to_shell_exec' => true,
1516
'binary_operator_spaces' => true,
1617
'blank_line_after_namespace' => true,
1718
'blank_line_after_opening_tag' => true,
19+
'blank_line_before_return' => false, // Deprecated
1820
'blank_line_before_statement' => true,
1921
'braces' => true,
2022
'cast_spaces' => true,
2123
'class_attributes_separation' => ['elements' => ['method', 'property']], // const are often grouped with other related const
2224
'class_definition' => true,
23-
'class_keyword_remove' => false, // ::class keyword gives us beter support in IDE
25+
'class_keyword_remove' => false, // ::class keyword gives us better support in IDE
2426
'combine_consecutive_issets' => true,
2527
'combine_consecutive_unsets' => true,
28+
'combine_nested_dirname' => true,
29+
'comment_to_phpdoc' => true,
2630
'compact_nullable_typehint' => true,
2731
'concat_space' => ['spacing' => 'one'],
32+
'constant_case' => true,
33+
'date_time_immutable' => true,
2834
'declare_equal_normalize' => true,
2935
'declare_strict_types' => true,
3036
'dir_constant' => true,
@@ -35,39 +41,57 @@ return PhpCsFixer\Config::create()
3541
'elseif' => true,
3642
'encoding' => true,
3743
'ereg_to_preg' => true,
44+
'error_suppression' => true,
3845
'escape_implicit_backslashes' => true,
3946
'explicit_indirect_variable' => false, // I feel it makes the code actually harder to read
40-
'explicit_string_variable' => true,
47+
'explicit_string_variable' => false, // I feel it makes the code actually harder to read
48+
'final_class' => false, // We need non-final classes
4149
'final_internal_class' => true,
50+
'final_public_method_for_abstract_class' => false, // We need non-final methods
51+
'final_static_access' => true,
52+
'fopen_flag_order' => true,
53+
'fopen_flags' => true,
4254
'full_opening_tag' => true,
55+
'fully_qualified_strict_types' => true,
4356
'function_declaration' => true,
4457
'function_to_constant' => true,
4558
'function_typehint_space' => true,
4659
'general_phpdoc_annotation_remove' => false, // No use for that
47-
'hash_to_slash_comment' => true,
60+
'global_namespace_import' => true,
61+
'hash_to_slash_comment' => false, // Deprecated
4862
'header_comment' => false, // We don't use common header in all our files
63+
'heredoc_indentation' => false, // Requires PHP >= 7.3
4964
'heredoc_to_nowdoc' => false, // Not sure about this one
65+
'implode_call' => true,
5066
'include' => true,
5167
'increment_style' => true,
5268
'indentation_type' => true,
53-
'is_null' => ['use_yoda_style' => false],
54-
'linebreak_after_opening_tag' => true,
69+
'is_null' => true,
5570
'line_ending' => true,
71+
'linebreak_after_opening_tag' => true,
5672
'list_syntax' => ['syntax' => 'short'],
73+
'logical_operators' => true,
5774
'lowercase_cast' => true,
58-
'lowercase_constants' => true,
75+
'lowercase_constants' => false, // Deprecated
5976
'lowercase_keywords' => true,
77+
'lowercase_static_reference' => true,
6078
'magic_constant_casing' => true,
79+
'magic_method_casing' => true,
6180
'mb_str_functions' => true,
6281
'method_argument_space' => true,
6382
'method_chaining_indentation' => true,
64-
'method_separation' => true,
83+
'method_separation' => false, // Deprecated
6584
'modernize_types_casting' => true,
6685
'multiline_comment_opening_closing' => true,
86+
'multiline_whitespace_before_semicolons' => true,
87+
'native_constant_invocation' => false, // Micro optimization that look messy
6788
'native_function_casing' => true,
6889
'native_function_invocation' => false, // I suppose this would be best, but I am still unconvinced about the visual aspect of it
90+
'native_function_type_declaration_casing' => true,
6991
'new_with_braces' => true,
7092
'no_alias_functions' => true,
93+
'no_alternative_syntax' => true,
94+
'no_binary_string' => true,
7195
'no_blank_lines_after_class_opening' => true,
7296
'no_blank_lines_after_phpdoc' => true,
7397
'no_blank_lines_before_namespace' => false, // we want 1 blank line before namespace
@@ -77,46 +101,71 @@ return PhpCsFixer\Config::create()
77101
'no_empty_phpdoc' => true,
78102
'no_empty_statement' => true,
79103
'no_extra_blank_lines' => true,
104+
'no_extra_consecutive_blank_lines' => false, // Deprecated
80105
'no_homoglyph_names' => true,
81106
'no_leading_import_slash' => true,
82107
'no_leading_namespace_whitespace' => true,
83108
'no_mixed_echo_print' => true,
84109
'no_multiline_whitespace_around_double_arrow' => true,
85-
'no_multiline_whitespace_before_semicolons' => true,
86-
'non_printable_character' => true,
110+
'no_multiline_whitespace_before_semicolons' => false, // Deprecated
87111
'no_null_property_initialization' => true,
88112
'no_php4_constructor' => true,
89-
'normalize_index_brace' => true,
90113
'no_short_bool_cast' => true,
91114
'no_short_echo_tag' => true,
92115
'no_singleline_whitespace_before_semicolons' => true,
93116
'no_spaces_after_function_name' => true,
94117
'no_spaces_around_offset' => true,
95118
'no_spaces_inside_parenthesis' => true,
96119
'no_superfluous_elseif' => true,
97-
'not_operator_with_space' => false, // No we prefer to keep '!' without spaces
98-
'not_operator_with_successor_space' => false, // idem
120+
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
99121
'no_trailing_comma_in_list_call' => true,
100122
'no_trailing_comma_in_singleline_array' => true,
101-
'no_trailing_whitespace_in_comment' => true,
102123
'no_trailing_whitespace' => true,
124+
'no_trailing_whitespace_in_comment' => true,
103125
'no_unneeded_control_parentheses' => true,
104126
'no_unneeded_curly_braces' => true,
105127
'no_unneeded_final_method' => true,
106128
'no_unreachable_default_argument_value' => true,
129+
'no_unset_cast' => true,
130+
'no_unset_on_property' => true,
107131
'no_unused_imports' => true,
108132
'no_useless_else' => true,
109133
'no_useless_return' => true,
110134
'no_whitespace_before_comma_in_array' => true,
111135
'no_whitespace_in_blank_line' => true,
136+
'non_printable_character' => true,
137+
'normalize_index_brace' => true,
138+
'not_operator_with_space' => false, // No we prefer to keep '!' without spaces
139+
'not_operator_with_successor_space' => false, // idem
140+
'nullable_type_declaration_for_default_null_value' => true,
112141
'object_operator_without_whitespace' => true,
113142
'ordered_class_elements' => false, // We prefer to keep some freedom
114143
'ordered_imports' => true,
144+
'ordered_interfaces' => true,
145+
'php_unit_construct' => true,
146+
'php_unit_dedicate_assert' => true,
147+
'php_unit_dedicate_assert_internal_type' => true,
148+
'php_unit_expectation' => true,
149+
'php_unit_fqcn_annotation' => true,
150+
'php_unit_internal_class' => false, // Because tests are excluded from package
151+
'php_unit_method_casing' => true,
152+
'php_unit_mock' => true,
153+
'php_unit_mock_short_will_return' => true,
154+
'php_unit_namespaced' => true,
155+
'php_unit_no_expectation_annotation' => true,
156+
'php_unit_ordered_covers' => true,
157+
'php_unit_set_up_tear_down_visibility' => true,
158+
'php_unit_size_class' => false, // That seems extra work to maintain for little benefits
159+
'php_unit_strict' => false, // We sometime actually need assertEquals
160+
'php_unit_test_annotation' => true,
161+
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
162+
'php_unit_test_class_requires_covers' => false, // We don't care as much as we should about coverage
115163
'phpdoc_add_missing_param_annotation' => true,
116164
'phpdoc_align' => false, // Waste of time
117165
'phpdoc_annotation_without_dot' => true,
118166
'phpdoc_indent' => true,
119167
'phpdoc_inline_tag' => true,
168+
'phpdoc_line_span' => true,
120169
'phpdoc_no_access' => true,
121170
'phpdoc_no_alias_tag' => true,
122171
'phpdoc_no_empty_return' => true,
@@ -129,43 +178,46 @@ return PhpCsFixer\Config::create()
129178
'phpdoc_single_line_var_spacing' => true,
130179
'phpdoc_summary' => false, // We usually don't generate documentation so punctuation is not important
131180
'phpdoc_to_comment' => true,
181+
'phpdoc_to_param_type' => false, // Because experimental, but interesting for one shot use
182+
'phpdoc_to_return_type' => false, // idem
132183
'phpdoc_trim' => true,
133-
'phpdoc_types_order' => true,
184+
'phpdoc_trim_consecutive_blank_line_separation' => true,
134185
'phpdoc_types' => true,
186+
'phpdoc_types_order' => true,
187+
'phpdoc_var_annotation_correct_order' => true,
135188
'phpdoc_var_without_name' => true,
136-
'php_unit_construct' => true,
137-
'php_unit_dedicate_assert' => true,
138-
'php_unit_expectation' => true,
139-
'php_unit_fqcn_annotation' => true,
140-
'php_unit_mock' => true,
141-
'php_unit_namespaced' => true,
142-
'php_unit_no_expectation_annotation' => true,
143-
'php_unit_strict' => false, // We sometime actually need assertEquals
144-
'php_unit_test_annotation' => true,
145-
'php_unit_test_class_requires_covers' => false, // We don't care as much as we should about coverage
146189
'pow_to_exponentiation' => true,
190+
'pre_increment' => false, // Deprecated
147191
'protected_to_private' => true,
148192
'psr0' => true,
149193
'psr4' => true,
150194
'random_api_migration' => true,
195+
'return_assignment' => false, // Sometimes useful for clarity or debug
151196
'return_type_declaration' => true,
152197
'self_accessor' => true,
198+
'self_static_accessor' => true,
153199
'semicolon_after_instruction' => false, // We prefer to keep .phtml files without semicolon
200+
'set_type_to_cast' => true,
154201
'short_scalar_cast' => true,
155-
'silenced_deprecation_error' => true,
202+
'silenced_deprecation_error' => false, // Deprecated
203+
'simple_to_complex_string_variable' => false, // Would differ from TypeScript without obvious advantages
156204
'simplified_null_return' => false, // Even if technically correct we prefer to be explicit
157205
'single_blank_line_at_eof' => true,
158206
'single_blank_line_before_namespace' => true,
159207
'single_class_element_per_statement' => true,
160208
'single_import_per_statement' => true,
161209
'single_line_after_imports' => true,
162210
'single_line_comment_style' => true,
211+
'single_line_throw' => false, // I don't see any reason for having a special case for Exception
163212
'single_quote' => true,
213+
'single_trait_insert_per_statement' => true,
164214
'space_after_semicolon' => true,
215+
'standardize_increment' => true,
165216
'standardize_not_equals' => true,
166217
'static_lambda' => false, // Risky if we can't guarantee nobody use `bindTo()`
167218
'strict_comparison' => true,
168219
'strict_param' => true,
220+
'string_line_ending' => true,
169221
'switch_case_semicolon_to_colon' => true,
170222
'switch_case_space' => true,
171223
'ternary_operator_spaces' => true,

src/UploadMiddleware.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
2323

2424
/**
2525
* Process the request and return either a modified request or the original one
26-
*
27-
* @param ServerRequestInterface $request
28-
*
29-
* @return ServerRequestInterface
3026
*/
3127
public function processRequest(ServerRequestInterface $request): ServerRequestInterface
3228
{
@@ -42,10 +38,6 @@ public function processRequest(ServerRequestInterface $request): ServerRequestIn
4238

4339
/**
4440
* Inject uploaded files defined in the 'map' key into the 'variables' key
45-
*
46-
* @param ServerRequestInterface $request
47-
*
48-
* @return ServerRequestInterface
4941
*/
5042
private function parseUploadedFiles(ServerRequestInterface $request): ServerRequestInterface
5143
{
@@ -78,8 +70,6 @@ private function parseUploadedFiles(ServerRequestInterface $request): ServerRequ
7870

7971
/**
8072
* Validates that the request meet our expectations
81-
*
82-
* @param ServerRequestInterface $request
8373
*/
8474
private function validateParsedBody(ServerRequestInterface $request): void
8575
{

src/UploadType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use GraphQL\Type\Definition\ScalarType;
1010
use GraphQL\Utils\Utils;
1111
use Psr\Http\Message\UploadedFileInterface;
12+
use UnexpectedValueException;
1213

1314
class UploadType extends ScalarType
1415
{
@@ -46,7 +47,7 @@ public function serialize($value)
4647
public function parseValue($value)
4748
{
4849
if (!$value instanceof UploadedFileInterface) {
49-
throw new \UnexpectedValueException('Could not get uploaded file, be sure to conform to GraphQL multipart request specification. Instead got: ' . Utils::printSafe($value));
50+
throw new UnexpectedValueException('Could not get uploaded file, be sure to conform to GraphQL multipart request specification. Instead got: ' . Utils::printSafe($value));
5051
}
5152

5253
return $value;

tests/UploadMiddlewareTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Psr\Http\Message\ServerRequestInterface;
2323
use Psr\Http\Message\UploadedFileInterface;
2424
use Psr\Http\Server\RequestHandlerInterface;
25+
use stdClass;
2526

2627
class UploadMiddlewareTest extends TestCase
2728
{
@@ -30,7 +31,7 @@ class UploadMiddlewareTest extends TestCase
3031
*/
3132
private $middleware;
3233

33-
public function setUp(): void
34+
protected function setUp(): void
3435
{
3536
$this->middleware = new UploadMiddleware();
3637
}
@@ -61,7 +62,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
6162

6263
// The request should be forward to processRequest()
6364
$request = new ServerRequest();
64-
$middleware->expects($this->once())->method('processRequest')->with($request);
65+
$middleware->expects(self::once())->method('processRequest')->with($request);
6566

6667
$actualResponse = $middleware->process($request, $handler);
6768
self::assertSame($response, $actualResponse, 'should return the mocked response');
@@ -148,7 +149,7 @@ public function testInvalidRequestShouldThrows(): void
148149
$request = new ServerRequest();
149150
$request = $request
150151
->withHeader('content-type', ['multipart/form-data'])
151-
->withParsedBody(new \stdClass());
152+
->withParsedBody(new stdClass());
152153

153154
$this->expectException(RequestError::class);
154155
$this->expectExceptionMessage('GraphQL Server expects JSON object or array, but got []');
@@ -160,7 +161,7 @@ public function testOtherContentTypeShouldNotBeTouched(): void
160161
$request = new ServerRequest();
161162
$request = $request
162163
->withHeader('content-type', ['application/json'])
163-
->withParsedBody(new \stdClass());
164+
->withParsedBody(new stdClass());
164165

165166
$processedRequest = $this->middleware->processRequest($request);
166167
self::assertSame($request, $processedRequest);
@@ -206,17 +207,13 @@ public function testCanUploadFileWithStandardServer(): void
206207
$response = $server->executePsrRequest($processedRequest);
207208

208209
$expected = ['testUpload' => 'Uploaded file was image.jpg (image/jpeg) with description: foo bar'];
209-
$this->assertSame($expected, $response->data);
210+
self::assertSame($expected, $response->data);
210211
}
211212

212213
/**
213-
* @param string $query
214214
* @param mixed[] $variables
215215
* @param string[][] $map
216216
* @param UploadedFile[] $files
217-
* @param string $operation
218-
*
219-
* @return ServerRequestInterface
220217
*/
221218
private function createRequest(string $query, array $variables, array $map, array $files, string $operation): ServerRequestInterface
222219
{

tests/UploadTypeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use GraphQL\Upload\UploadType;
1111
use GraphQLTests\Upload\Psr7\PsrUploadedFileStub;
1212
use PHPUnit\Framework\TestCase;
13+
use UnexpectedValueException;
1314

1415
class UploadTypeTest extends TestCase
1516
{
@@ -24,7 +25,7 @@ public function testCanParseUploadedFileInstance(): void
2425
public function testCannotParseNonUploadedFileInstance(): void
2526
{
2627
$type = new UploadType();
27-
$this->expectException(\UnexpectedValueException::class);
28+
$this->expectException(UnexpectedValueException::class);
2829
$this->expectExceptionMessage('Could not get uploaded file, be sure to conform to GraphQL multipart request specification. Instead got: foo');
2930

3031
$type->parseValue('foo');

0 commit comments

Comments
 (0)