From 52e6cc897686cdfa3fb3d3bf8ad7ccad20f2fa97 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 24 Dec 2023 09:58:30 +0100 Subject: [PATCH 1/2] Update PHP-CS-Fixer configuration --- .php-cs-fixer.dist.php | 68 +++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 9da232f..5f45cf7 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -25,6 +25,10 @@ 'backtick_to_shell_exec' => true, 'binary_operator_spaces' => [ 'operators' => [ + '*=' => 'align_single_space_minimal', + '+=' => 'align_single_space_minimal', + '-=' => 'align_single_space_minimal', + '/=' => 'align_single_space_minimal', '=' => 'align_single_space_minimal', '=>' => 'align_single_space_minimal', ], @@ -57,6 +61,14 @@ 'yield_from', ], ], + 'blank_lines_before_namespace' => [ + 'max_line_breaks' => 1, + 'min_line_breaks' => 0, + ], + 'braces_position' => [ + 'anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end', + 'anonymous_functions_opening_brace' => 'next_line_unless_newline_at_signature_end', + ], 'cast_spaces' => true, 'class_attributes_separation' => [ 'elements' => [ @@ -70,15 +82,11 @@ 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, 'combine_nested_dirname' => true, - 'compact_nullable_typehint' => true, + 'compact_nullable_type_declaration' => true, 'concat_space' => ['spacing' => 'one'], 'constant_case' => true, 'control_structure_braces' => true, 'control_structure_continuation_position' => true, - 'curly_braces_position' => [ - 'anonymous_functions_opening_brace' => 'next_line_unless_newline_at_signature_end', - 'anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end', - ], 'declare_equal_normalize' => ['space' => 'none'], 'declare_parentheses' => true, 'declare_strict_types' => true, @@ -94,7 +102,6 @@ 'fully_qualified_strict_types' => true, 'function_declaration' => true, 'function_to_constant' => true, - 'function_typehint_space' => true, 'get_class_to_class_keyword' => true, 'global_namespace_import' => [ 'import_classes' => true, @@ -106,9 +113,10 @@ 'implode_call' => true, 'include' => true, 'increment_style' => [ - 'style' => PhpCsFixer\Fixer\Operator\IncrementStyleFixer::STYLE_POST, + 'style' => 'post', ], 'indentation_type' => true, + 'integer_literal_case' => true, 'is_null' => true, 'lambda_not_used_import' => true, 'line_ending' => true, @@ -122,6 +130,8 @@ 'method_argument_space' => [ 'on_multiline' => 'ensure_fully_multiline', ], + 'method_chaining_indentation' => true, + 'modernize_strpos' => true, 'modernize_types_casting' => true, 'multiline_comment_opening_closing' => true, 'multiline_whitespace_before_semicolons' => true, @@ -132,10 +142,10 @@ '@internal', ], ], - 'native_function_type_declaration_casing' => true, - 'new_with_braces' => [ - 'named_class' => false, + 'native_type_declaration_casing' => true, + 'new_with_parentheses' => [ 'anonymous_class' => false, + 'named_class' => false, ], 'no_alias_functions' => true, 'no_alias_language_construct_call' => true, @@ -143,7 +153,6 @@ 'no_binary_string' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, - 'no_blank_lines_before_namespace' => true, 'no_break_comment' => true, 'no_closing_tag' => true, 'no_empty_comment' => true, @@ -154,15 +163,15 @@ 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_mixed_echo_print' => ['use' => 'print'], - 'no_multiple_statements_per_line' => true, 'no_multiline_whitespace_around_double_arrow' => true, + 'no_multiple_statements_per_line' => true, 'no_null_property_initialization' => true, 'no_php4_constructor' => true, 'no_short_bool_cast' => true, 'no_singleline_whitespace_before_semicolons' => true, + 'no_space_around_double_colon' => true, 'no_spaces_after_function_name' => true, 'no_spaces_around_offset' => true, - 'no_spaces_inside_parenthesis' => true, 'no_superfluous_elseif' => true, 'no_superfluous_phpdoc_tags' => [ 'allow_mixed' => true, @@ -171,15 +180,17 @@ 'no_trailing_whitespace' => true, 'no_trailing_whitespace_in_comment' => true, 'no_trailing_whitespace_in_string' => true, + 'no_unneeded_braces' => true, 'no_unneeded_control_parentheses' => true, - 'no_unneeded_curly_braces' => true, 'no_unneeded_final_method' => true, 'no_unneeded_import_alias' => true, 'no_unreachable_default_argument_value' => true, 'no_unset_cast' => true, 'no_unset_on_property' => true, 'no_unused_imports' => true, + 'no_useless_concat_operator' => true, 'no_useless_else' => true, + 'no_useless_nullsafe_operator' => true, 'no_useless_return' => true, 'no_useless_sprintf' => true, 'no_whitespace_before_comma_in_array' => true, @@ -187,6 +198,7 @@ 'non_printable_character' => true, 'normalize_index_brace' => true, 'object_operator_without_whitespace' => true, + 'octal_notation' => true, 'operator_linebreak' => [ 'only_booleans' => true, 'position' => 'end', @@ -217,9 +229,9 @@ ], 'ordered_imports' => [ 'imports_order' => [ - PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_CONST, - PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_FUNCTION, - PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_CLASS, + 'const', + 'function', + 'class', ] ], 'ordered_interfaces' => [ @@ -227,6 +239,7 @@ 'order' => 'alpha', ], 'ordered_traits' => true, + 'ordered_types' => true, 'php_unit_set_up_tear_down_visibility' => true, 'php_unit_test_case_static_method_calls' => [ 'call_type' => 'this', @@ -250,6 +263,7 @@ 'uses', ], ], + 'phpdoc_param_order' => true, 'phpdoc_return_self_reference' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, @@ -257,7 +271,7 @@ 'phpdoc_summary' => true, 'phpdoc_tag_casing' => true, 'phpdoc_tag_type' => true, - 'phpdoc_to_comment' => true, + 'phpdoc_to_comment' => false, 'phpdoc_trim' => true, 'phpdoc_trim_consecutive_blank_line_separation' => true, 'phpdoc_types' => ['groups' => ['simple', 'meta']], @@ -279,15 +293,20 @@ 'single_class_element_per_statement' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, + 'single_line_comment_spacing' => true, 'single_quote' => true, 'single_space_around_construct' => true, 'single_trait_insert_per_statement' => true, 'space_after_semicolon' => true, + 'spaces_inside_parentheses' => [ + 'space' => 'none', + ], 'standardize_increment' => true, 'standardize_not_equals' => true, 'statement_indentation' => true, 'static_lambda' => true, 'strict_param' => true, + 'string_length_to_empty'=> true, 'string_line_ending' => true, 'switch_case_semicolon_to_colon' => true, 'switch_case_space' => true, @@ -297,13 +316,18 @@ 'ternary_to_null_coalescing' => true, 'trailing_comma_in_multiline' => [ 'elements' => [ - 'arrays' + 'arguments', + 'arrays', + 'match', ] ], 'trim_array_spaces' => true, - 'types_spaces' => [ - 'space' => 'none', + 'type_declaration_spaces' => [ + 'elements' => [ + 'function', + ], ], + 'types_spaces' => true, 'unary_operator_spaces' => true, 'visibility_required' => [ 'elements' => [ @@ -316,4 +340,6 @@ 'whitespace_after_comma_in_array' => true, ]); +$config->setCacheFile(__DIR__ . '/.php-cs-fixer.cache/' . sha1(@trim((string) @shell_exec('git rev-parse --abbrev-ref HEAD')))); + return $config; From 085df786b17d0671c2b8ace1ec58f3aced4fe186 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 24 Dec 2023 09:58:43 +0100 Subject: [PATCH 2/2] Fix CS/WS issues --- src/Parser.php | 4 +-- src/exceptions/AmbiguousOptionException.php | 4 +-- .../OptionDoesNotAllowArgumentException.php | 4 +-- ...RequiredOptionArgumentMissingException.php | 4 +-- src/exceptions/UnknownOptionException.php | 4 +-- tests/ParserTest.php | 36 +++++++++---------- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 795e95b..7186290 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -93,7 +93,7 @@ public function parse(array $argv, string $shortOptions, array $longOptions = nu substr($arg, 2), $longOptions, $options, - $argv + $argv, ); continue; @@ -103,7 +103,7 @@ public function parse(array $argv, string $shortOptions, array $longOptions = nu substr($arg, 1), $shortOptions, $options, - $argv + $argv, ); } diff --git a/src/exceptions/AmbiguousOptionException.php b/src/exceptions/AmbiguousOptionException.php index a99f636..99eb625 100644 --- a/src/exceptions/AmbiguousOptionException.php +++ b/src/exceptions/AmbiguousOptionException.php @@ -19,8 +19,8 @@ public function __construct(string $option) parent::__construct( sprintf( 'Option "%s" is ambiguous', - $option - ) + $option, + ), ); } } diff --git a/src/exceptions/OptionDoesNotAllowArgumentException.php b/src/exceptions/OptionDoesNotAllowArgumentException.php index 0aad29a..7fea616 100644 --- a/src/exceptions/OptionDoesNotAllowArgumentException.php +++ b/src/exceptions/OptionDoesNotAllowArgumentException.php @@ -19,8 +19,8 @@ public function __construct(string $option) parent::__construct( sprintf( 'Option "%s" does not allow an argument', - $option - ) + $option, + ), ); } } diff --git a/src/exceptions/RequiredOptionArgumentMissingException.php b/src/exceptions/RequiredOptionArgumentMissingException.php index d2a930b..9add49a 100644 --- a/src/exceptions/RequiredOptionArgumentMissingException.php +++ b/src/exceptions/RequiredOptionArgumentMissingException.php @@ -19,8 +19,8 @@ public function __construct(string $option) parent::__construct( sprintf( 'Required argument for option "%s" is missing', - $option - ) + $option, + ), ); } } diff --git a/src/exceptions/UnknownOptionException.php b/src/exceptions/UnknownOptionException.php index e98d9fd..560c7ad 100644 --- a/src/exceptions/UnknownOptionException.php +++ b/src/exceptions/UnknownOptionException.php @@ -19,8 +19,8 @@ public function __construct(string $option) parent::__construct( sprintf( 'Unknown option "%s"', - $option - ) + $option, + ), ); } } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 2ffd425..385edb3 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -39,8 +39,8 @@ public function testParsesShortOptionsWithOptionalValues(): void 'myArgument', '-f', ], - 'f::' - ) + 'f::', + ), ); } @@ -75,8 +75,8 @@ public function testParsesLongOptionsWithValues(): void 'parameter-n', ], '', - ['exec', 'conf=', 'optn=='] - ) + ['exec', 'conf=', 'optn=='], + ), ); } @@ -110,8 +110,8 @@ public function testParsesShortOptionsWithValues(): void '-ocontent-of-o', 'parameter-n', ], - 'xc:o::' - ) + 'xc:o::', + ), ); } @@ -136,8 +136,8 @@ public function testParsesLongOptionsAfterArguments(): void '--colors', ], '', - ['colors=='] - ) + ['colors=='], + ), ); } @@ -161,8 +161,8 @@ public function testParsesShortOptionsAfterArguments(): void 'myArgument', '-v', ], - 'v' - ) + 'v', + ), ); } @@ -175,8 +175,8 @@ public function testReturnsEmptyResultWhenNotOptionsArePassed(): void ], (new Parser)->parse( [], - 'v' - ) + 'v', + ), ); } @@ -191,7 +191,7 @@ public function testRaisesAnExceptionForUnknownLongOption(): void '--foo', ], '', - ['colors'] + ['colors'], ); } @@ -206,7 +206,7 @@ public function testRaisesAnExceptionForUnknownShortOption(): void 'myArgument', '-v', ], - '' + '', ); } @@ -221,7 +221,7 @@ public function testRaisesAnExceptionWhenRequiredArgumentForLongOptionIsMissing( '--foo', ], '', - ['foo='] + ['foo='], ); } @@ -236,7 +236,7 @@ public function testRaisesAnExceptionWhenRequiredArgumentForShortOptionIsMissing 'myArgument', '-f', ], - 'f:' + 'f:', ); } @@ -251,7 +251,7 @@ public function testRaisesAnExceptionWhenLongOptionIsAmbiguous(): void '--col', ], '', - ['columns', 'colors'] + ['columns', 'colors'], ); } @@ -266,7 +266,7 @@ public function testRaisesAnExceptionWhenAnArgumentIsGivenForLongOptionThatDoesN '--foo=bar', ], '', - ['foo'] + ['foo'], ); } }