[TOOLS] Update PHP CS fixer and adjust configuration

这个提交包含在:
Hugo Sales 2021-10-10 08:40:06 +01:00 提交者 Diogo Peralta Cordeiro
父节点 7aad58b440
当前提交 703e66fd2e
签署人:: diogo
GPG 密钥 ID: 18D2D35001FBFAB0
共有 2 个文件被更改,包括 151 次插入51 次删除

3
.gitignore vendored
查看文件

@ -16,8 +16,9 @@
###< symfony/phpunit-bridge ###
###> friendsofphp/php-cs-fixer ###
!.php_cs
!.php-cs-fixer.php
/.php_cs.cache
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###
###> phpunit/phpunit ###

查看文件

@ -1,42 +1,46 @@
<?php
declare(strict_types = 1);
/*
* This document has been generated with
* https://mlocati.github.io/php-cs-fixer-configurator/#version:2.16.1|configurator
* https://mlocati.github.io/php-cs-fixer-configurator/#version:3.2.1|configurator
* you can change this configuration by importing this file.
*/
return PhpCsFixer\Config::create()
$config = new PhpCsFixer\Config();
return $config
->setRiskyAllowed(true)
->setRules([
// Each line of multi-line DocComments must have an asterisk [PSR-5] and must be aligned with the first one.
'align_multiline_comment' => ['comment_type' => 'phpdocs_like'],
// PHP arrays should be declared using the configured syntax.
'array_syntax' => ['syntax' => 'short'],
// Binary operators should be surrounded by space as configured.
'binary_operator_spaces' => [
'default' => 'align_single_space_minimal',
'operators' => ['??' => 'align'],
],
// There MUST be one blank line after the namespace declaration.
'blank_line_after_namespace' => true,
// Each element of an array must be indented exactly once.
'array_indentation' => true,
// Converts simple usages of `array_push($x, $y);` to `$x[] = $y;`.
'array_push' => true,
// PHP arrays should be declared using the configured syntax.
'array_syntax' => ['syntax' => 'short'],
// Use the null coalescing assignment operator `??=` where possible.
'assign_null_coalescing_to_coalesce_equal' => true,
// Binary operators should be surrounded by space as configured.
'binary_operator_spaces' => ['default' => 'align_single_space_minimal', 'operators' => ['??' => 'align']],
// There MUST be one blank line after the namespace declaration.
'blank_line_after_namespace' => true,
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
'blank_line_after_opening_tag' => false,
'blank_line_after_opening_tag' => true,
// The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
'braces' => ['allow_single_line_closure' => true, 'position_after_functions_and_oop_constructs' => 'next',
// 'allow_single_line_functions' => true, // Awaiting PR merge...
],
'braces' => ['allow_single_line_anonymous_class_with_empty_body' => true, 'allow_single_line_closure' => true, 'position_after_functions_and_oop_constructs' => 'next'],
// A single space or none should be between cast and variable.
'cast_spaces' => true,
// Class, trait and interface elements must be separated with one blank line.
'class_attributes_separation' => false,
// Whitespace around the keywords of a class, trait or interfaces definition should be one space.
'class_definition' => ['single_item_single_line' => true, 'single_line' => true],
// Using `isset($var) &&` multiple times should be done in one call.
'combine_consecutive_issets' => true,
// Calling `unset` on multiple items should be done in one call.
'combine_consecutive_unsets' => true,
// Replace multiple nested calls of `dirname` by only one call with second `$level` parameter. Requires PHP >= 7.0.
'combine_nested_dirname' => true,
// Comments with annotation should be docblock when used on structural elements.
'comment_to_phpdoc' => false,
// Remove extra spaces in a nullable typehint.
'compact_nullable_typehint' => true,
// Concatenation should be spaced according configuration.
@ -45,8 +49,20 @@ return PhpCsFixer\Config::create()
'constant_case' => true,
// Equal sign in declare statement should be surrounded by spaces or not following configuration.
'declare_equal_normalize' => ['space' => 'single'],
// There must not be spaces around `declare` statement parentheses.
'declare_parentheses' => true,
// Force strict types declaration in all files. Requires PHP >= 7.0.
'declare_strict_types' => true,
// Replaces `dirname(__FILE__)` expression with equivalent `__DIR__` constant.
'dir_constant' => true,
// Replaces short-echo `<?=` with long format `<?php echo`/`<?php print` syntax, or vice-versa.
'echo_tag_syntax' => true,
// The keyword `elseif` should be used instead of `else if` so that all control keywords look like single words.
'elseif' => true,
// Empty loop-body must be in configured style.
'empty_loop_body' => true,
// Empty loop-condition must be in configured style.
'empty_loop_condition' => true,
// PHP code MUST use only UTF-8 without BOM (remove BOM).
'encoding' => true,
// Replace deprecated `ereg` regular expression functions with `preg`.
@ -65,14 +81,30 @@ return PhpCsFixer\Config::create()
'function_declaration' => ['closure_function_spacing' => 'one'],
// Ensure single space between function's argument and its typehint.
'function_typehint_space' => true,
// Imports or fully qualifies global classes/functions/constants.
'global_namespace_import' => true,
// Heredoc/nowdoc content must be properly indented. Requires PHP >= 7.3.
'heredoc_indentation' => true,
// Convert `heredoc` to `nowdoc` where possible.
'heredoc_to_nowdoc' => true,
// Function `implode` must be called with 2 arguments in the documented order.
'implode_call' => true,
// Pre- or post-increment and decrement operators should be used if possible.
'increment_style' => true,
// Code MUST use configured indentation type.
'indentation_type' => true,
// Lambda must not import variables it doesn't use.
'lambda_not_used_import' => true,
// All PHP files must use same line ending.
'line_ending' => true,
// Ensure there is no code on the same line as the PHP open tag.
'linebreak_after_opening_tag' => true,
// List (`array` destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1.
'list_syntax' => ['syntax' => 'short'],
// Use `&&` and `||` logical operators instead of `and` and `or`.
'logical_operators' => true,
// Cast should be written in lower case.
'lowercase_cast' => true,
// PHP keywords MUST be in lower case.
'lowercase_keywords' => true,
// Class static references `self`, `static` and `parent` MUST be in lower case.
@ -81,6 +113,14 @@ return PhpCsFixer\Config::create()
'magic_constant_casing' => true,
// Magic method definitions and calls must be using the correct casing.
'magic_method_casing' => true,
// Replace non multibyte-safe functions with corresponding mb function.
'mb_str_functions' => true,
// In method arguments and method call, there MUST NOT be a space before each comma and there MUST be one space after each comma. Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line.
'method_argument_space' => ['after_heredoc' => true, 'on_multiline' => 'ensure_fully_multiline'],
// Method chaining MUST be properly indented. Method chaining with different levels of indentation is not supported.
'method_chaining_indentation' => true,
// Replace `strpos()` calls with `str_starts_with()` or `str_contains()` if possible.
'modernize_strpos' => true,
// Replaces `intval`, `floatval`, `doubleval`, `strval` and `boolval` function calls with according type casting operator.
'modernize_types_casting' => true,
// DocBlocks must start with two asterisks, multiline comments must start with a single asterisk, after the opening slash. Both must end with a single asterisk before the closing slash.
@ -88,13 +128,17 @@ return PhpCsFixer\Config::create()
// Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.
'multiline_whitespace_before_semicolons' => true,
// Add leading `\` before constant invocation of internal constant to speed up resolving. Constant name match is case-sensitive, except for `null`, `false` and `true`.
'native_constant_invocation' => false,
'native_constant_invocation' => true,
// Function defined by PHP should be called using the correct casing.
'native_function_casing' => true,
// Add leading `\` before function invocation to speed up resolving.
'native_function_invocation' => false,
'native_function_invocation' => true,
// Native type hints for functions should use the correct case.
'native_function_type_declaration_casing' => true,
// Master language constructs shall be used instead of aliases.
'no_alias_language_construct_call' => true,
// Replace control structure alternative syntax to use braces.
'no_alternative_syntax' => true,
// There should be no empty lines after class opening brace.
'no_blank_lines_after_class_opening' => true,
// There should not be blank lines between docblock and the documented element.
@ -107,7 +151,7 @@ return PhpCsFixer\Config::create()
'no_empty_comment' => true,
// There should not be empty PHPDoc blocks.
'no_empty_phpdoc' => true,
// Remove useless semicolon statements.
// Remove useless (semicolon) statements.
'no_empty_statement' => true,
// Removes extra blank lines and/or blank lines following configuration.
'no_extra_blank_lines' => true,
@ -123,18 +167,18 @@ return PhpCsFixer\Config::create()
'no_null_property_initialization' => true,
// Short cast `bool` using double exclamation mark should not be used.
'no_short_bool_cast' => true,
// Replace short-echo `<?=` with long format `<?php echo` syntax.
'no_short_echo_tag' => true,
// Single-line whitespace before closing semicolon are prohibited.
'no_singleline_whitespace_before_semicolons' => true,
// There must be no space around double colons (also called Scope Resolution Operator or Paamayim Nekudotayim).
'no_space_around_double_colon' => true,
// When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis.
'no_spaces_after_function_name' => true,
// There MUST NOT be spaces around offset braces.
'no_spaces_around_offset' => true,
// There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis.
'no_spaces_inside_parenthesis' => true,
// Replaces superfluous `elseif` with `if`.
'no_superfluous_elseif' => false,
// Removes `@param`, `@return` and `@var` tags that don't provide any useful information.
'no_superfluous_phpdoc_tags' => true,
// Remove trailing commas in list function calls.
'no_trailing_comma_in_list_call' => true,
// PHP single-line arrays should not have trailing comma.
@ -150,13 +194,9 @@ return PhpCsFixer\Config::create()
// In function arguments there must not be arguments with default values before non-default ones.
'no_unreachable_default_argument_value' => true,
// Variables must be set `null` instead of using `(unset)` casting.
'no_unset_cast' => false,
// Properties should be set to `null` instead of using `unset`.
'no_unset_on_property' => true,
'no_unset_cast' => true,
// Unused `use` statements must be removed.
'no_unused_imports' => true,
// There should not be useless `else` cases.
'no_useless_else' => false,
// There should not be an empty `return` statement at the end of a function.
'no_useless_return' => true,
// In array declaration, there MUST NOT be a whitespace before each comma.
@ -167,22 +207,32 @@ return PhpCsFixer\Config::create()
'non_printable_character' => true,
// Array index should always be written by using square braces.
'normalize_index_brace' => true,
// There should not be space before or after object `T_OBJECT_OPERATOR` `->`.
// Adds or removes `?` before type declarations for parameters with a default `null` value.
'nullable_type_declaration_for_default_null_value' => true,
// There should not be space before or after object operators `->` and `?->`.
'object_operator_without_whitespace' => true,
// Operators - when multiline - must always be at the beginning or at the end of the line.
'operator_linebreak' => true,
// Ordering `use` statements.
'ordered_imports' => true,
// Orders the elements of classes/interfaces/traits.
'ordered_class_elements' => false,
// PHPUnit assertion method calls like `->assertSame(true, $foo)` should be written with dedicated method like `->assertTrue($foo)`.
'php_unit_construct' => true,
// PHPUnit assertions like `assertInternalType`, `assertFileExists`, should be used over `assertTrue`.
'php_unit_dedicate_assert' => true,
// PHPUnit assertions like `assertIsArray` should be used over `assertInternalType`.
'php_unit_dedicate_assert_internal_type' => true,
// Usages of `->setExpectedException*` methods MUST be replaced by `->expectException*` methods.
'php_unit_expectation' => true,
// PHPUnit annotations should be a FQCNs including a root namespace.
'php_unit_fqcn_annotation' => true,
// Enforce camel (or snake) case for PHPUnit test methods, following configuration.
'php_unit_method_casing' => true,
// Usage of PHPUnit's mock e.g. `->will($this->returnValue(..))` must be replaced by its shorter equivalent such as `->willReturn(...)`.
'php_unit_mock_short_will_return' => true,
// Order `@covers` annotation of PHPUnit tests.
'php_unit_ordered_covers' => true,
// PHPUnit classes MUST be used in namespaced version, e.g. `\PHPUnit\Framework\TestCase` instead of `\PHPUnit_Framework_TestCase`.
'php_unit_namespaced' => true,
// Usages of `@expectedException*` annotations MUST be replaced by `->setExpectedException*` methods.
'php_unit_no_expectation_annotation' => true,
// Changes the visibility of the `setUp()` and `tearDown()` functions of PHPUnit to `protected`, to match the PHPUnit TestCase.
'php_unit_set_up_tear_down_visibility' => true,
// PHPUnit methods like `assertSame` should be used instead of `assertEquals`.
@ -193,16 +243,26 @@ return PhpCsFixer\Config::create()
'phpdoc_add_missing_param_annotation' => true,
// All items of the given phpdoc tags must be either left-aligned or (by default) aligned vertically.
'phpdoc_align' => true,
// PHPDoc annotation descriptions should not be a sentence.
'phpdoc_annotation_without_dot' => true,
// Docblocks should have the same indentation as the documented subject.
'phpdoc_indent' => true,
// Fix PHPDoc inline tags, make `@inheritdoc` always inline.
'phpdoc_inline_tag' => true,
// Fixes PHPDoc inline tags.
'phpdoc_inline_tag_normalizer' => true,
// Changes doc blocks from single to multi line, or reversed. Works for class constants, properties and methods only.
'phpdoc_line_span' => true,
// `@access` annotations should be omitted from PHPDoc.
'phpdoc_no_access' => true,
// No alias PHPDoc tags should be used.
'phpdoc_no_alias_tag' => true,
// `@return void` and `@return null` annotations should be omitted from PHPDoc.
'phpdoc_no_empty_return' => true,
// Classy that does not inherit must not have `@inheritdoc` tags.
'phpdoc_no_useless_inheritdoc' => true,
// Annotations in PHPDoc should be ordered so that `@param` annotations come first, then `@throws` annotations, then `@return` annotations.
'phpdoc_order' => true,
// Order phpdoc tags by value.
'phpdoc_order_by_value' => ['annotations' => ['covers', 'throws']],
// The type of `@return` annotations of methods returning a reference to itself must the configured one.
'phpdoc_return_self_reference' => true,
// Scalar types should always be written in the same form. `int` not `integer`, `bool` not `boolean`, `float` not `real` or `double`.
@ -210,7 +270,17 @@ return PhpCsFixer\Config::create()
// Annotations in PHPDoc should be grouped together so that annotations of the same type immediately follow each other, and annotations of a different type are separated by a single blank line.
'phpdoc_separation' => true,
// Single line `@var` PHPDoc should have proper spacing.
'phpdoc_single_line_var_spacing' => false,
'phpdoc_single_line_var_spacing' => true,
// Fixes casing of PHPDoc tags.
'phpdoc_tag_casing' => true,
// EXPERIMENTAL: Takes `@param` annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.
'phpdoc_to_param_type' => true,
// EXPERIMENTAL: Takes `@var` annotation of non-mixed types and adjusts accordingly the property signature. Requires PHP >= 7.4.
'phpdoc_to_property_type' => true,
// EXPERIMENTAL: Takes `@return` annotation of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.
'phpdoc_to_return_type' => true,
// PHPDoc should start and end with content, excluding the very first and last line of the docblocks.
'phpdoc_trim' => true,
// Removes extra blank lines after summary and after description in PHPDoc.
'phpdoc_trim_consecutive_blank_line_separation' => true,
// The correct case must be used for standard PHP types in PHPDoc.
@ -219,8 +289,14 @@ return PhpCsFixer\Config::create()
'phpdoc_types_order' => true,
// `@var` and `@type` annotations must have type and name in the correct order.
'phpdoc_var_annotation_correct_order' => true,
// Class names should match the file name.
'psr4' => true,
// Converts `pow` to the `**` operator.
'pow_to_exponentiation' => true,
// Replaces `rand`, `srand`, `getrandmax` functions calls with their `mt_*` analogs or `random_int`.
'random_api_migration' => true,
// Callables must be called without using `call_user_func*` when possible.
'regular_callable_call' => true,
// Local, dynamic and directly referenced variables should not be assigned and directly returned by a function or method.
'return_assignment' => true,
// There should be one or no space before colon, and one space after it in return type declarations, according to configuration.
'return_type_declaration' => true,
// Inside class or interface element `self` should be preferred to the class name itself.
@ -233,18 +309,26 @@ return PhpCsFixer\Config::create()
'short_scalar_cast' => true,
// Converts explicit variables in double-quoted strings and heredoc syntax from simple to complex format (`${` to `{$`).
'simple_to_complex_string_variable' => true,
// Simplify `if` control structures that return the boolean result of their condition.
'simplified_if_return' => true,
// A return statement wishing to return `void` should not return `null`.
'simplified_null_return' => true,
// A PHP file without end tag must always end with a single empty line feed.
'single_blank_line_at_eof' => true,
// There should be exactly one blank line before a namespace declaration.
'single_blank_line_before_namespace' => true,
// There MUST be one use keyword per declaration.
'single_import_per_statement' => true,
// There MUST NOT be more than one property or constant declared per statement.
'single_class_element_per_statement' => true,
// There MUST be one use keyword per declaration.
'single_import_per_statement' => true,
// Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
'single_line_after_imports' => true,
// Single-line comments and multi-line comments with only one line of actual content should use the `//` syntax.
'single_line_comment_style' => true,
// Convert double quotes to single quotes for simple strings.
'single_quote' => true,
// Ensures a single space after language constructs.
'single_space_after_construct' => true,
// Each trait `use` must be done as single statement.
'single_trait_insert_per_statement' => true,
// Fix whitespace after a semicolon.
@ -253,26 +337,41 @@ return PhpCsFixer\Config::create()
'standardize_increment' => true,
// Replace all `<>` with `!=`.
'standardize_not_equals' => true,
// String tests for empty must be done against `''`, not with `strlen`.
'string_length_to_empty' => true,
// A case should be followed by a colon and not a semicolon.
'switch_case_semicolon_to_colon' => true,
// Removes extra spaces between colon and case value.
'switch_case_space' => true,
// Switch case must not be ended with `continue` but with `break`.
'switch_continue_to_break' => true,
// Standardize spaces around ternary operator.
'ternary_operator_spaces' => true,
// PHP multi-line arrays should have a trailing comma.
'trailing_comma_in_multiline_array' => true,
// Use the Elvis operator `?:` where possible.
'ternary_to_elvis_operator' => true,
// Use `null` coalescing operator `??` where possible. Requires PHP >= 7.0.
'ternary_to_null_coalescing' => true,
// Multi-line arrays, arguments list and parameters list must have a trailing comma.
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'parameters']],
// Arrays should be formatted like function/method arguments, without leading or trailing single line space.
'trim_array_spaces' => true,
// A single space or none should be around union type operator.
'types_spaces' => true,
// Unary operators should be placed adjacent to their operands.
'unary_operator_spaces' => true,
// Anonymous functions with one-liner return statement must use arrow functions.
'use_arrow_functions' => true,
// Visibility MUST be declared on all properties and methods; `abstract` and `final` MUST be declared before the visibility; `static` MUST be declared after the visibility.
'visibility_required' => true,
// In array declaration, there MUST be a whitespace after each comma.
'whitespace_after_comma_in_array' => true,
])
->setFinder(PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('var')
->exclude('docker')
->exclude('src/Entity')
->notPath('src/Core/DB/DefaultSettings.php')
->in(__DIR__)
->setFinder(
PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('var')
->exclude('docker')
->exclude('src/Entity')
->notPath('src/Core/DB/DefaultSettings.php')
->in(__DIR__),
);