Browse Source

Fix checking for default config used in rule sets

Kuba Werłos 3 years ago
parent
commit
942dfb7794

+ 0 - 2
doc/ruleSets/PHP71Migration.rst

@@ -10,5 +10,3 @@ Rules
 - `@PHP70Migration <./PHP70Migration.rst>`_
 - `list_syntax <./../rules/list_notation/list_syntax.rst>`_
 - `visibility_required <./../rules/class_notation/visibility_required.rst>`_
-  config:
-  ``['elements' => ['const', 'method', 'property']]``

+ 0 - 2
doc/ruleSets/PSR12.rst

@@ -32,5 +32,3 @@ Rules
 - `single_trait_insert_per_statement <./../rules/class_notation/single_trait_insert_per_statement.rst>`_
 - `ternary_operator_spaces <./../rules/operator/ternary_operator_spaces.rst>`_
 - `visibility_required <./../rules/class_notation/visibility_required.rst>`_
-  config:
-  ``['elements' => ['const', 'method', 'property']]``

+ 0 - 1
doc/ruleSets/Symfony.rst

@@ -120,6 +120,5 @@ Rules
 - `trailing_comma_in_multiline_array <./../rules/array_notation/trailing_comma_in_multiline_array.rst>`_
 - `trim_array_spaces <./../rules/array_notation/trim_array_spaces.rst>`_
 - `unary_operator_spaces <./../rules/operator/unary_operator_spaces.rst>`_
-- `visibility_required <./../rules/class_notation/visibility_required.rst>`_
 - `whitespace_after_comma_in_array <./../rules/array_notation/whitespace_after_comma_in_array.rst>`_
 - `yoda_style <./../rules/control_structure/yoda_style.rst>`_

+ 5 - 15
doc/rules/class_notation/visibility_required.rst

@@ -68,29 +68,19 @@ Rule sets
 The rule is part of the following rule sets:
 
 @PHP71Migration
-  Using the `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the config below:
-
-  ``['elements' => ['const', 'method', 'property']]``
+  Using the `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the default config.
 
 @PHP73Migration
-  Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the config below:
-
-  ``['elements' => ['const', 'method', 'property']]``
+  Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the default config.
 
 @PHP74Migration
-  Using the `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the config below:
-
-  ``['elements' => ['const', 'method', 'property']]``
+  Using the `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the default config.
 
 @PHP80Migration
-  Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the config below:
-
-  ``['elements' => ['const', 'method', 'property']]``
+  Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the default config.
 
 @PSR12
-  Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``visibility_required`` rule with the config below:
-
-  ``['elements' => ['const', 'method', 'property']]``
+  Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``visibility_required`` rule with the default config.
 
 @PSR2
   Using the `@PSR2 <./../../ruleSets/PSR2.rst>`_ rule set will enable the ``visibility_required`` rule with the config below:

+ 1 - 7
src/RuleSet/Sets/PHP71MigrationSet.php

@@ -26,13 +26,7 @@ final class PHP71MigrationSet extends AbstractRuleSetDescription
         return [
             '@PHP70Migration' => true,
             'list_syntax' => true,
-            'visibility_required' => [
-                'elements' => [
-                    'const',
-                    'method',
-                    'property',
-                ],
-            ],
+            'visibility_required' => true,
         ];
     }
 

+ 1 - 7
src/RuleSet/Sets/PSR12Set.php

@@ -55,13 +55,7 @@ final class PSR12Set extends AbstractRuleSetDescription
             'single_blank_line_before_namespace' => true,
             'single_trait_insert_per_statement' => true,
             'ternary_operator_spaces' => true,
-            'visibility_required' => [
-                'elements' => [
-                    'const',
-                    'method',
-                    'property',
-                ],
-            ],
+            'visibility_required' => true,
         ];
     }
 

+ 0 - 1
src/RuleSet/Sets/SymfonySet.php

@@ -171,7 +171,6 @@ final class SymfonySet extends AbstractRuleSetDescription
             'trailing_comma_in_multiline_array' => true,
             'trim_array_spaces' => true,
             'unary_operator_spaces' => true,
-            'visibility_required' => true,
             'whitespace_after_comma_in_array' => true,
             'yoda_style' => true,
         ];

+ 24 - 4
tests/RuleSet/RuleSetTest.php

@@ -94,10 +94,11 @@ final class RuleSetTest extends TestCase
             $defaultConfig[$option->getName()] = $option->getDefault();
         }
 
-        ksort($defaultConfig);
-        ksort($ruleConfig);
-
-        static::assertNotSame($defaultConfig, $ruleConfig, sprintf('Rule "%s" (in RuleSet "%s") has default config passed.', $ruleName, $setName));
+        static::assertNotSame(
+            $this->sortNestedArray($defaultConfig),
+            $this->sortNestedArray($ruleConfig),
+            sprintf('Rule "%s" (in RuleSet "%s") has default config passed.', $ruleName, $setName)
+        );
     }
 
     /**
@@ -406,6 +407,25 @@ final class RuleSetTest extends TestCase
         }
     }
 
+    private function sortNestedArray(array $array)
+    {
+        foreach ($array as $key => $element) {
+            if (!\is_array($element)) {
+                continue;
+            }
+            $array[$key] = $this->sortNestedArray($element);
+        }
+
+        // sort by key if associative, by values otherwise
+        if (array_keys($array) === range(0, \count($array) - 1)) {
+            sort($array);
+        } else {
+            ksort($array);
+        }
+
+        return $array;
+    }
+
     private function findInSets(array $sets, string $ruleName, $config)
     {
         $duplicates = [];