Browse Source

Drop diff-format

Dariusz Ruminski 4 years ago
parent
commit
3b77699d3f

+ 2 - 2
UPGRADE-v3.md

@@ -8,8 +8,8 @@ CLI options
 
 | 2.x              | 3.0             | Description                                     | Note                                   |
 | ---------------- | --------------- | ----------------------------------------------- | -------------------------------------- |
-| --diff-format    | --diff-format   | Type of differ                                  | Allowed value `sbd` was removed,       |
-|                  |                 |                                                 | new default is `udiff`                 |
+| --diff-format    |                 | Type of differ                                  | Option was removed, all diffs are now  |
+|                  |                 |                                                 | `udiff`                                |
 | --show-progress  | --show-progress | Type of progress indicator                      | Allowed values were modified:          |
 |                  |                 |                                                 | `run-in` and `estimating` was removed, |
 |                  |                 |                                                 | `estimating-max` was removed to `dots` |

+ 1 - 6
doc/usage.rst

@@ -71,12 +71,7 @@ Complete configuration for rules can be supplied using a ``json`` formatted stri
 
 The ``--dry-run`` flag will run the fixer without making changes to your files.
 
-The ``--diff`` flag can be used to let the fixer output all the changes it makes.
-
-The ``--diff-format`` option allows to specify in which format the fixer should output the changes it makes:
-
-* ``udiff``: unified diff format;
-* ``sbd``: Sebastianbergmann/diff format (default when using `--diff` without specifying `diff-format`).
+The ``--diff`` flag can be used to let the fixer output all the changes it makes in `udiff` format`.
 
 The ``--allow-risky`` option (pass ``yes`` or ``no``) allows you to set whether risky rules may run. Default value is taken from config file.
 A rule is considered risky if it could change code behaviour. By default no risky rules are run.

+ 0 - 2
src/Console/Command/FixCommand.php

@@ -107,7 +107,6 @@ final class FixCommand extends Command
                     new InputOption('using-cache', '', InputOption::VALUE_REQUIRED, 'Does cache should be used (can be yes or no).'),
                     new InputOption('cache-file', '', InputOption::VALUE_REQUIRED, 'The path to the cache file.'),
                     new InputOption('diff', '', InputOption::VALUE_NONE, 'Also produce diff for each file.'),
-                    new InputOption('diff-format', '', InputOption::VALUE_REQUIRED, 'Specify diff format.'),
                     new InputOption('format', '', InputOption::VALUE_REQUIRED, 'To output results in other formats.'),
                     new InputOption('stop-on-violation', '', InputOption::VALUE_NONE, 'Stop execution on first violation.'),
                     new InputOption('show-progress', '', InputOption::VALUE_REQUIRED, 'Type of progress indicator (none, dots).'),
@@ -144,7 +143,6 @@ final class FixCommand extends Command
                 'cache-file' => $input->getOption('cache-file'),
                 'format' => $input->getOption('format'),
                 'diff' => $input->getOption('diff'),
-                'diff-format' => $input->getOption('diff-format'),
                 'stop-on-violation' => $input->getOption('stop-on-violation'),
                 'verbosity' => $verbosity,
                 'show-progress' => $input->getOption('show-progress'),

+ 0 - 2
src/Console/Command/HelpCommand.php

@@ -110,8 +110,6 @@ The <comment>--dry-run</comment> flag will run the fixer without making changes
 
 The <comment>--diff</comment> flag can be used to let the fixer output all the changes it makes.
 
-The <comment>--diff-format</comment> option allows to specify in which format the fixer should output the changes it makes:
-
 * <comment>null</comment>: no diff;
 * <comment>udiff</comment>: unified diff format.
 

+ 3 - 32
src/Console/ConfigurationResolver.php

@@ -119,7 +119,6 @@ final class ConfigurationResolver
         'cache-file' => null,
         'config' => null,
         'diff' => null,
-        'diff-format' => null,
         'dry-run' => null,
         'format' => null,
         'path' => [],
@@ -265,38 +264,10 @@ final class ConfigurationResolver
     public function getDiffer()
     {
         if (null === $this->differ) {
-            $mapper = [
-                'null' => static function () { return new NullDiffer(); },
-                'udiff' => static function () { return new UnifiedDiffer(); },
-            ];
-
-            if (!$this->options['diff']) {
-                $defaultOption = 'null';
-            } else {
-                $defaultOption = 'udiff';
-            }
-
-            $option = isset($this->options['diff-format'])
-                ? $this->options['diff-format']
-                : $defaultOption;
-
-            if (!\is_string($option)) {
-                throw new InvalidConfigurationException(sprintf(
-                    '"diff-format" must be a string, "%s" given.',
-                    \gettype($option)
-                ));
-            }
-
-            if (is_subclass_of($option, DifferInterface::class)) {
-                $this->differ = new $option();
-            } elseif (!isset($mapper[$option])) {
-                throw new InvalidConfigurationException(sprintf(
-                    '"diff-format" must be any of "%s", got "%s".',
-                    implode('", "', array_keys($mapper)),
-                    $option
-                ));
+            if ($this->options['diff']) {
+                $this->differ = new UnifiedDiffer();
             } else {
-                $this->differ = $mapper[$option]();
+                $this->differ = new NullDiffer();
             }
         }
 

+ 2 - 53
tests/Console/ConfigurationResolverTest.php

@@ -20,7 +20,6 @@ use PhpCsFixer\Console\ConfigurationResolver;
 use PhpCsFixer\Finder;
 use PhpCsFixer\Linter\LinterInterface;
 use PhpCsFixer\Tests\Fixtures\DeprecatedFixer;
-use PhpCsFixer\Tests\Fixtures\FakeDiffer;
 use PhpCsFixer\Tests\TestCase;
 use PhpCsFixer\ToolInfo;
 use Symfony\Component\Console\Output\OutputInterface;
@@ -1022,7 +1021,7 @@ final class ConfigurationResolverTest extends TestCase
 
         $options = $definition->getOptions();
         static::assertSame(
-            ['path-mode', 'allow-risky', 'config', 'dry-run', 'rules', 'using-cache', 'cache-file', 'diff', 'diff-format', 'format', 'stop-on-violation', 'show-progress'],
+            ['path-mode', 'allow-risky', 'config', 'dry-run', 'rules', 'using-cache', 'cache-file', 'diff', 'format', 'stop-on-violation', 'show-progress'],
             array_keys($options),
             'Expected options mismatch, possibly test needs updating.'
         );
@@ -1035,7 +1034,6 @@ final class ConfigurationResolverTest extends TestCase
             'rules' => 'php_unit_construct',
             'using-cache' => 'no',
             'diff' => true,
-            'diff-format' => 'udiff',
             'format' => 'json',
             'stop-on-violation' => true,
         ]);
@@ -1053,40 +1051,18 @@ final class ConfigurationResolverTest extends TestCase
     /**
      * @param string           $expected
      * @param null|bool|string $diffConfig
-     * @param null|string      $differConfig
      *
      * @dataProvider provideDifferCases
      */
-    public function testResolveDiffer($expected, $diffConfig, $differConfig = null)
+    public function testResolveDiffer($expected, $diffConfig)
     {
         $resolver = $this->createConfigurationResolver([
             'diff' => $diffConfig,
-            'diff-format' => $differConfig,
         ]);
 
         static::assertInstanceOf($expected, $resolver->getDiffer());
     }
 
-    public function testCustomDiffer()
-    {
-        $resolver = $this->createConfigurationResolver([
-            'diff-format' => FakeDiffer::class,
-        ]);
-
-        static::assertInstanceOf(FakeDiffer::class, $resolver->getDiffer());
-    }
-
-    public function testCustomDifferMustBeAString()
-    {
-        $resolver = $this->createConfigurationResolver([
-            'diff-format' => new FakeDiffer(),
-        ]);
-
-        $this->expectExceptionMessage('"diff-format" must be a string, "object" given');
-
-        $resolver->getDiffer();
-    }
-
     public function provideDifferCases()
     {
         return [
@@ -1102,36 +1078,9 @@ final class ConfigurationResolverTest extends TestCase
                 \PhpCsFixer\Differ\UnifiedDiffer::class,
                 true,
             ],
-            [
-                \PhpCsFixer\Differ\UnifiedDiffer::class,
-                true,
-                'udiff',
-            ],
-            [
-                \PhpCsFixer\Differ\UnifiedDiffer::class,
-                false,
-                'udiff',
-            ],
-            [
-                \PhpCsFixer\Differ\UnifiedDiffer::class,
-                null,
-                'udiff',
-            ],
         ];
     }
 
-    public function testResolveUnknownDiffer()
-    {
-        $resolver = $this->createConfigurationResolver([
-            'diff-format' => 'XXX',
-        ]);
-
-        $this->expectException(\InvalidArgumentException::class);
-        $this->expectExceptionMessageMatches('#^"diff\-format" must be any of "null", "udiff", got "XXX"\.$#');
-
-        $resolver->getDiffer();
-    }
-
     public function testResolveConfigFileOverridesDefault()
     {
         $dir = __DIR__.'/../Fixtures/ConfigurationResolverConfigFile/case_8';