Browse Source

Drop mapping of strings to boolean option other than yes/no

Dariusz Ruminski 4 years ago
parent
commit
af788a8c57

+ 1 - 1
doc/usage.rst

@@ -102,7 +102,7 @@ automatically fix anything:
     $ cat foo.php | php php-cs-fixer.phar fix --diff -
 
 Finally, if you don't need BC kept on CLI level, you might use `PHP_CS_FIXER_FUTURE_MODE` to start using options that
-would be default in next MAJOR release (unified differ, estimating, full-width progress indicator):
+would be default in next MAJOR release and to forbid using deprecated configuration:
 
 .. code-block:: console
 

+ 1 - 1
src/Console/Command/HelpCommand.php

@@ -135,7 +135,7 @@ automatically fix anything:
     <info>$ cat foo.php | php %command.full_name% --diff -</info>
 
 Finally, if you don't need BC kept on CLI level, you might use `PHP_CS_FIXER_FUTURE_MODE` to start using options that
-would be default in next MAJOR release (unified differ, dots, full-width progress indicator):
+would be default in next MAJOR release and to forbid using deprecated configuration:
 
     <info>$ PHP_CS_FIXER_FUTURE_MODE=1 php %command.full_name% -v --diff</info>
 

+ 1 - 12
src/Console/ConfigurationResolver.php

@@ -904,9 +904,6 @@ final class ConfigurationResolver
     private function resolveOptionBooleanValue($optionName)
     {
         $value = $this->options[$optionName];
-        if (\is_bool($value)) {
-            return $value;
-        }
 
         if (!\is_string($value)) {
             throw new InvalidConfigurationException(sprintf('Expected boolean or string value for option "%s".', $optionName));
@@ -920,15 +917,7 @@ final class ConfigurationResolver
             return false;
         }
 
-        $message = sprintf('Expected "yes" or "no" for option "%s", other values are deprecated and support will be removed in 3.0. Got "%s", this implicitly set the option to "false".', $optionName, $value);
-
-        if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
-            throw new InvalidConfigurationException("{$message} This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.");
-        }
-
-        @trigger_error($message, E_USER_DEPRECATED);
-
-        return false;
+        throw new InvalidConfigurationException(sprintf('Expected "yes" or "no" for option "%s", got "%s".', $optionName, $value));
     }
 
     private static function separatedContextLessInclude($path)

+ 4 - 5
tests/Console/Command/FixCommandTest.php

@@ -40,12 +40,11 @@ final class FixCommandTest extends TestCase
         );
     }
 
-    /**
-     * @group legacy
-     * @expectedDeprecation Expected "yes" or "no" for option "using-cache", other values are deprecated and support will be removed in 3.0. Got "not today", this implicitly set the option to "false".
-     */
     public function testEmptyFormatValue()
     {
+        $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class);
+        $this->expectExceptionMessage('Expected "yes" or "no" for option "using-cache", got "not today".');
+
         $cmdTester = $this->doTestExecute(
             [
                 '--using-cache' => 'not today',
@@ -53,7 +52,7 @@ final class FixCommandTest extends TestCase
             ]
         );
 
-        static::assertSame(0, $cmdTester->getStatusCode(), "Expected exit code mismatch. Output:\n".$cmdTester->getDisplay());
+        $cmdTester->getStatusCode();
     }
 
     /**

+ 11 - 16
tests/Console/ConfigurationResolverTest.php

@@ -757,9 +757,9 @@ final class ConfigurationResolverTest extends TestCase
     }
 
     /**
-     * @param bool             $expected
-     * @param bool             $configValue
-     * @param null|bool|string $passed
+     * @param bool        $expected
+     * @param bool        $configValue
+     * @param null|string $passed
      *
      * @dataProvider provideResolveBooleanOptionCases
      */
@@ -873,9 +873,9 @@ final class ConfigurationResolverTest extends TestCase
     }
 
     /**
-     * @param bool             $expected
-     * @param bool             $configValue
-     * @param null|bool|string $passed
+     * @param bool        $expected
+     * @param bool        $configValue
+     * @param null|string $passed
      *
      * @dataProvider provideResolveBooleanOptionCases
      */
@@ -1033,7 +1033,7 @@ final class ConfigurationResolverTest extends TestCase
             'config' => null,
             'dry-run' => true,
             'rules' => 'php_unit_construct',
-            'using-cache' => false,
+            'using-cache' => 'no',
             'diff' => true,
             'diff-format' => 'udiff',
             'format' => 'json',
@@ -1145,28 +1145,23 @@ final class ConfigurationResolverTest extends TestCase
         static::assertSame('xml', $resolver->getReporter()->getFormat());
     }
 
-    /**
-     * @group legacy
-     * @expectedDeprecation Expected "yes" or "no" for option "allow-risky", other values are deprecated and support will be removed in 3.0. Got "yes please", this implicitly set the option to "false".
-     */
     public function testDeprecationOfPassingOtherThanNoOrYes()
     {
+        $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class);
+        $this->expectExceptionMessage('Expected "yes" or "no" for option "allow-risky", got "yes please".');
+
         $resolver = $this->createConfigurationResolver(['allow-risky' => 'yes please']);
 
-        static::assertFalse($resolver->getRiskyAllowed());
+        $resolver->getRiskyAllowed();
     }
 
     public function provideResolveBooleanOptionCases()
     {
         return [
             [true, true, 'yes'],
-            [true, true, true],
             [true, false, 'yes'],
-            [true, false, true],
             [false, true, 'no'],
-            [false, true, false],
             [false, false, 'no'],
-            [false, false, false],
             [true, true, null],
             [false, false, null],
         ];