Browse Source

feat: Update PSR2, PSR12 and PER-CS2 with `single_space_around_construct` config (#8171)

SpacePossum 6 months ago
parent
commit
1e4b0f237b

+ 1 - 1
dev-tools/phpstan/baseline.php

@@ -1473,7 +1473,7 @@ $ignoreErrors[] = [
 ];
 $ignoreErrors[] = [
 	// identifier: offsetAccess.notFound
-	'message' => '#^Offset \'as\'\\|\'use_lambda\' might not exist on array\\<string, int\\|null\\>\\.$#',
+	'message' => '#^Offset \'as\'\\|\'else\'\\|\'elseif\'\\|\'use_lambda\' might not exist on array\\<string, int\\|null\\>\\.$#',
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/Fixer/LanguageConstruct/SingleSpaceAroundConstructFixer.php',
 ];

+ 6 - 1
doc/ruleSets/PER-CS2.0.rst

@@ -9,6 +9,7 @@ Rules
 
 - `@PER-CS1.0 <./PER-CS1.0.rst>`_
 - `array_indentation <./../rules/whitespace/array_indentation.rst>`_
+- `array_syntax <./../rules/array_notation/array_syntax.rst>`_
 - `cast_spaces <./../rules/cast_notation/cast_spaces.rst>`_
 - `concat_space <./../rules/operator/concat_space.rst>`_ with config:
 
@@ -24,7 +25,11 @@ Rules
   ``['anonymous_class' => false]``
 
 - `single_line_empty_body <./../rules/basic/single_line_empty_body.rst>`_
+- `single_space_around_construct <./../rules/language_construct/single_space_around_construct.rst>`_ with config:
+
+  ``['constructs_followed_by_a_single_space' => ['abstract', 'as', 'case', 'catch', 'class', 'const', 'const_import', 'do', 'else', 'elseif', 'enum', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'if', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'private', 'protected', 'public', 'readonly', 'static', 'switch', 'trait', 'try', 'type_colon', 'use', 'use_lambda', 'while'], 'constructs_preceded_by_a_single_space' => ['as', 'else', 'elseif', 'use_lambda']]``
+
 - `trailing_comma_in_multiline <./../rules/control_structure/trailing_comma_in_multiline.rst>`_ with config:
 
-  ``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``
+  ``['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]``
 

+ 8 - 0
doc/ruleSets/PSR12.rst

@@ -29,6 +29,10 @@ Rules
 - `lowercase_static_reference <./../rules/casing/lowercase_static_reference.rst>`_
 - `new_with_parentheses <./../rules/operator/new_with_parentheses.rst>`_
 - `no_blank_lines_after_class_opening <./../rules/class_notation/no_blank_lines_after_class_opening.rst>`_
+- `no_extra_blank_lines <./../rules/whitespace/no_extra_blank_lines.rst>`_ with config:
+
+  ``['tokens' => ['use']]``
+
 - `no_leading_import_slash <./../rules/import/no_leading_import_slash.rst>`_
 - `no_whitespace_in_blank_line <./../rules/whitespace/no_whitespace_in_blank_line.rst>`_
 - `ordered_class_elements <./../rules/class_notation/ordered_class_elements.rst>`_ with config:
@@ -45,6 +49,10 @@ Rules
 
   ``['group_to_single_imports' => false]``
 
+- `single_space_around_construct <./../rules/language_construct/single_space_around_construct.rst>`_ with config:
+
+  ``['constructs_followed_by_a_single_space' => ['abstract', 'as', 'case', 'catch', 'class', 'const_import', 'do', 'else', 'elseif', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'if', 'insteadof', 'interface', 'namespace', 'new', 'private', 'protected', 'public', 'static', 'switch', 'trait', 'try', 'use', 'use_lambda', 'while'], 'constructs_preceded_by_a_single_space' => ['as', 'else', 'elseif', 'use_lambda']]``
+
 - `single_trait_insert_per_statement <./../rules/class_notation/single_trait_insert_per_statement.rst>`_
 - `ternary_operator_spaces <./../rules/operator/ternary_operator_spaces.rst>`_
 - `unary_operator_spaces <./../rules/operator/unary_operator_spaces.rst>`_ with config:

+ 4 - 0
doc/ruleSets/PSR2.rst

@@ -37,6 +37,10 @@ Rules
 
 - `single_import_per_statement <./../rules/import/single_import_per_statement.rst>`_
 - `single_line_after_imports <./../rules/import/single_line_after_imports.rst>`_
+- `single_space_around_construct <./../rules/language_construct/single_space_around_construct.rst>`_ with config:
+
+  ``['constructs_followed_by_a_single_space' => ['abstract', 'as', 'case', 'catch', 'class', 'do', 'else', 'elseif', 'final', 'for', 'foreach', 'function', 'if', 'interface', 'namespace', 'private', 'protected', 'public', 'static', 'switch', 'trait', 'try', 'use_lambda', 'while'], 'constructs_preceded_by_a_single_space' => ['as', 'else', 'elseif', 'use_lambda']]``
+
 - `spaces_inside_parentheses <./../rules/whitespace/spaces_inside_parentheses.rst>`_
 - `statement_indentation <./../rules/whitespace/statement_indentation.rst>`_
 - `switch_case_semicolon_to_colon <./../rules/control_structure/switch_case_semicolon_to_colon.rst>`_

+ 0 - 1
doc/ruleSets/Symfony.rst

@@ -9,7 +9,6 @@ Rules
 
 - `@PER-CS2.0 <./PER-CS2.0.rst>`_
 - `align_multiline_comment <./../rules/phpdoc/align_multiline_comment.rst>`_
-- `array_syntax <./../rules/array_notation/array_syntax.rst>`_
 - `backtick_to_shell_exec <./../rules/alias/backtick_to_shell_exec.rst>`_
 - `binary_operator_spaces <./../rules/operator/binary_operator_spaces.rst>`_
 - `blank_line_before_statement <./../rules/whitespace/blank_line_before_statement.rst>`_ with config:

+ 3 - 0
doc/rules/array_notation/array_syntax.rst

@@ -50,6 +50,9 @@ Rule sets
 
 The rule is part of the following rule sets:
 
+- `@PER <./../../ruleSets/PER.rst>`_
+- `@PER-CS <./../../ruleSets/PER-CS.rst>`_
+- `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_
 - `@PHP54Migration <./../../ruleSets/PHP54Migration.rst>`_
 - `@PHP70Migration <./../../ruleSets/PHP70Migration.rst>`_
 - `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_

+ 3 - 3
doc/rules/control_structure/trailing_comma_in_multiline.rst

@@ -105,15 +105,15 @@ The rule is part of the following rule sets:
 
 - `@PER <./../../ruleSets/PER.rst>`_ with config:
 
-  ``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``
+  ``['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]``
 
 - `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
 
-  ``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``
+  ``['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]``
 
 - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
 
-  ``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``
+  ``['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]``
 
 - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ with config:
 

+ 25 - 1
doc/rules/language_construct/single_space_around_construct.rst

@@ -30,7 +30,7 @@ Default value: ``['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'clas
 
 List of constructs which must be preceded by a single space.
 
-Allowed values: a subset of ``['as', 'use_lambda']``
+Allowed values: a subset of ``['as', 'else', 'elseif', 'use_lambda']``
 
 Default value: ``['as', 'use_lambda']``
 
@@ -113,6 +113,30 @@ Rule sets
 
 The rule is part of the following rule sets:
 
+- `@PER <./../../ruleSets/PER.rst>`_ with config:
+
+  ``['constructs_followed_by_a_single_space' => ['abstract', 'as', 'case', 'catch', 'class', 'const', 'const_import', 'do', 'else', 'elseif', 'enum', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'if', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'private', 'protected', 'public', 'readonly', 'static', 'switch', 'trait', 'try', 'type_colon', 'use', 'use_lambda', 'while'], 'constructs_preceded_by_a_single_space' => ['as', 'else', 'elseif', 'use_lambda']]``
+
+- `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
+
+  ``['constructs_followed_by_a_single_space' => ['abstract', 'as', 'case', 'catch', 'class', 'const', 'const_import', 'do', 'else', 'elseif', 'enum', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'if', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'private', 'protected', 'public', 'readonly', 'static', 'switch', 'trait', 'try', 'type_colon', 'use', 'use_lambda', 'while'], 'constructs_preceded_by_a_single_space' => ['as', 'else', 'elseif', 'use_lambda']]``
+
+- `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
+
+  ``['constructs_followed_by_a_single_space' => ['abstract', 'as', 'case', 'catch', 'class', 'const_import', 'do', 'else', 'elseif', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'if', 'insteadof', 'interface', 'namespace', 'new', 'private', 'protected', 'public', 'static', 'switch', 'trait', 'try', 'use', 'use_lambda', 'while'], 'constructs_preceded_by_a_single_space' => ['as', 'else', 'elseif', 'use_lambda']]``
+
+- `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
+
+  ``['constructs_followed_by_a_single_space' => ['abstract', 'as', 'case', 'catch', 'class', 'const', 'const_import', 'do', 'else', 'elseif', 'enum', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'if', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'private', 'protected', 'public', 'readonly', 'static', 'switch', 'trait', 'try', 'type_colon', 'use', 'use_lambda', 'while'], 'constructs_preceded_by_a_single_space' => ['as', 'else', 'elseif', 'use_lambda']]``
+
+- `@PSR2 <./../../ruleSets/PSR2.rst>`_ with config:
+
+  ``['constructs_followed_by_a_single_space' => ['abstract', 'as', 'case', 'catch', 'class', 'do', 'else', 'elseif', 'final', 'for', 'foreach', 'function', 'if', 'interface', 'namespace', 'private', 'protected', 'public', 'static', 'switch', 'trait', 'try', 'use_lambda', 'while'], 'constructs_preceded_by_a_single_space' => ['as', 'else', 'elseif', 'use_lambda']]``
+
+- `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
+
+  ``['constructs_followed_by_a_single_space' => ['abstract', 'as', 'case', 'catch', 'class', 'const_import', 'do', 'else', 'elseif', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'if', 'insteadof', 'interface', 'namespace', 'new', 'private', 'protected', 'public', 'static', 'switch', 'trait', 'try', 'use', 'use_lambda', 'while'], 'constructs_preceded_by_a_single_space' => ['as', 'else', 'elseif', 'use_lambda']]``
+
 - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
 - `@Symfony <./../../ruleSets/Symfony.rst>`_
 

+ 20 - 0
doc/rules/whitespace/no_extra_blank_lines.rst

@@ -219,6 +219,26 @@ Rule sets
 
 The rule is part of the following rule sets:
 
+- `@PER <./../../ruleSets/PER.rst>`_ with config:
+
+  ``['tokens' => ['use']]``
+
+- `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
+
+  ``['tokens' => ['use']]``
+
+- `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
+
+  ``['tokens' => ['use']]``
+
+- `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
+
+  ``['tokens' => ['use']]``
+
+- `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
+
+  ``['tokens' => ['use']]``
+
 - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
 
   ``['tokens' => ['attribute', 'break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use']]``

+ 2 - 2
src/Fixer/ClassNotation/ProtectedToPrivateFixer.php

@@ -86,7 +86,7 @@ final class Sample
         foreach ($this->tokensAnalyzer->getClassyElements() as $index => $element) {
             $classIndex = $element['classIndex'];
 
-            if (!\array_key_exists($classIndex, $classesCandidate)) {
+            if (!isset($classesCandidate[$classIndex])) {
                 $classesCandidate[$classIndex] = $this->isClassCandidate($tokens, $classIndex);
             }
 
@@ -130,7 +130,7 @@ final class Sample
      *   - an Enum (PHP8.1+)
      *   - a class, which:
      *     - is not anonymous
-     *     - is not final
+     *     - is final
      *     - does not use traits
      *     - does not extend other class.
      */

Some files were not shown because too many files changed in this diff