Browse Source

Merge branch '2.18'

Dariusz Ruminski 4 years ago
parent
commit
9fcde235d2
3 changed files with 23 additions and 5 deletions
  1. 1 1
      dev-tools/install.sh
  2. 21 3
      src/RuleSet/RuleSet.php
  3. 1 1
      tests/FixerFactoryTest.php

+ 1 - 1
dev-tools/install.sh

@@ -20,7 +20,7 @@ cd "$(dirname "$0")"
 
 mkdir -p bin
 
-VERSION_CB="2.20.5"
+VERSION_CB="2.21.1"
 VERSION_SC="stable"
 
 echo λλλ checkbashisms

+ 21 - 3
src/RuleSet/RuleSet.php

@@ -39,13 +39,31 @@ class RuleSet implements RuleSetInterface
 
     public function __construct(array $set = [])
     {
-        foreach ($set as $key => $value) {
-            if (\is_int($key)) {
+        foreach ($set as $name => $value) {
+            if ('' === $name) {
+                throw new \InvalidArgumentException('Rule/set name must not be empty.');
+            }
+
+            if (\is_int($name)) {
                 throw new \InvalidArgumentException(sprintf('Missing value for "%s" rule/set.', $value));
             }
 
             if (true !== $value && false !== $value && !\is_array($value)) {
-                throw new InvalidFixerConfigurationException($key, 'Configuration must be an array and may not be empty.');
+                // @TODO drop me on 3.0
+                if (null === $value) {
+                    $messageForNullIssue = 'To disable the rule, use "FALSE" instead of "NULL".';
+                    if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
+                        throw new InvalidFixerConfigurationException($name, $messageForNullIssue);
+                    }
+
+                    @trigger_error($messageForNullIssue, E_USER_DEPRECATED);
+
+                    continue;
+                }
+
+                $message = '@' === $name[0] ? 'Set must be enabled (true) or disabled (false). Other values are not allowed.' : 'Rule must be enabled (true), disabled (false) or configured (non-empty, assoc array). Other values are not allowed.';
+
+                throw new InvalidFixerConfigurationException($name, $message);
             }
         }
 

+ 1 - 1
tests/FixerFactoryTest.php

@@ -308,7 +308,7 @@ final class FixerFactoryTest extends TestCase
             \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class
         );
         $this->expectExceptionMessage(
-            '[foo] Configuration must be an array and may not be empty.'
+            '[foo] Rule must be enabled (true), disabled (false) or configured (non-empty, assoc array). Other values are not allowed.'
         );
 
         $factory->useRuleSet(new RuleSet([