Browse Source

FixerConfiguration - better Resolver creation

Julien Falque 8 years ago
parent
commit
852339dc22

+ 33 - 29
README.rst

@@ -212,9 +212,9 @@ Choose from the list of available rules:
 
   Configuration options:
 
-  - ``align_double_arrow`` (``NULL``, ``false``, ``true``): whether to apply, remove or
+  - ``align_double_arrow`` (``false``, ``null``, ``true``): whether to apply, remove or
     ignore double arrows alignment; defaults to ``false``
-  - ``align_equals`` (``NULL``, ``false``, ``true``): whether to apply, remove or ignore
+  - ``align_equals`` (``false``, ``null``, ``true``): whether to apply, remove or ignore
     equals alignment; defaults to ``false``
 
 * **blank_line_after_namespace** [@PSR2, @Symfony]
@@ -289,14 +289,14 @@ Choose from the list of available rules:
 
   Force strict types declaration in all files. Requires PHP >= 7.0.
 
-  *Risky rule.*
+  *Risky rule: forcing strict types will stop non strict code from working.*
 
 * **dir_constant**
 
   Replaces ``dirname(__FILE__)`` expression with equivalent ``__DIR__``
   constant.
 
-  *Risky rule.*
+  *Risky rule: risky when the function ``dirname()`` is overridden.*
 
 * **elseif** [@PSR2, @Symfony]
 
@@ -311,7 +311,7 @@ Choose from the list of available rules:
 
   Replace deprecated ``ereg`` regular expression functions with preg.
 
-  *Risky rule.*
+  *Risky rule: risky if the ``ereg`` funcion is overridden.*
 
 * **full_opening_tag** [@PSR1, @PSR2, @Symfony]
 
@@ -321,7 +321,11 @@ Choose from the list of available rules:
 * **function_declaration** [@PSR2, @Symfony]
 
   Spaces should be properly placed in a function declaration.
-  *Configurable rule.*
+
+  Configuration options:
+
+  - ``closure_function_spacing`` (``'none'``, ``'one'``): spacing to use before open
+    parenthesis for closures; defaults to ``'one'``
 
 * **function_typehint_space** [@Symfony]
 
@@ -346,7 +350,7 @@ Choose from the list of available rules:
 
   Configuration options:
 
-  - ``commentType`` (``'PHPDoc'``, ``'comment'``): comment syntax type; defaults to
+  - ``commentType`` (``'comment'``, ``'PHPDoc'``): comment syntax type; defaults to
     ``'comment'``
   - ``header`` (``string``): proper header content; required
   - ``location`` (``'after_declare_strict'``, ``'after_open'``): the location of the
@@ -371,7 +375,7 @@ Choose from the list of available rules:
 
   Replaces is_null(parameter) expression with ``null === parameter``.
 
-  *Risky rule.*
+  *Risky rule: risky when the function ``is_null()`` is overridden.*
 
   Configuration options:
 
@@ -402,7 +406,7 @@ Choose from the list of available rules:
 
   Replace non multibyte-safe functions with corresponding mb function.
 
-  *Risky rule.*
+  *Risky rule: risky when any of the functions are overridden.*
 
 * **method_argument_space** [@PSR2, @Symfony]
 
@@ -418,7 +422,7 @@ Choose from the list of available rules:
   Replaces ``intval``, ``floatval``, ``doubleval``, ``strval`` and ``boolval``
   function calls with according type casting operator.
 
-  *Risky rule.*
+  *Risky rule: risky if any of the functions ``intval``, ``floatval``, ``doubleval``, ``strval`` or ``boolval`` are overridden.*
 
 * **native_function_casing** [@Symfony]
 
@@ -429,7 +433,7 @@ Choose from the list of available rules:
   Add leading ``\`` before function invocation of internal function to speed
   up resolving.
 
-  *Risky rule.*
+  *Risky rule: risky when any of the functions are overridden.*
 
   Configuration options:
 
@@ -443,7 +447,7 @@ Choose from the list of available rules:
 
   Master functions shall be used instead of aliases.
 
-  *Risky rule.*
+  *Risky rule: risky when any of the alias functions are overridden.*
 
 * **no_blank_lines_after_class_opening** [@Symfony]
 
@@ -511,7 +515,7 @@ Choose from the list of available rules:
 
   Convert PHP4-style constructors to ``__construct``.
 
-  *Risky rule.*
+  *Risky rule: risky when old style constructor being fixed is overridden or overrides parent one.*
 
 * **no_short_bool_cast** [@Symfony]
 
@@ -566,16 +570,16 @@ Choose from the list of available rules:
 
   Configuration options:
 
-  - ``control_statements`` (``array``): list of control statements to fix; defaults
-    to ``['break', 'clone', 'continue', 'echo_print', 'return',
-    'switch_case', 'yield']``
+  - ``statements`` (``array``): list of control statements to fix; defaults to
+    ``['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case',
+    'yield']``
 
 * **no_unreachable_default_argument_value**
 
   In function arguments there must not be arguments with default values
   before non-default ones.
 
-  *Risky rule.*
+  *Risky rule: modifies the signature of functions; therefore risky when using systems (such as some Symfony components) that rely on those (for example through reflection).*
 
 * **no_unused_imports** [@Symfony]
 
@@ -634,7 +638,7 @@ Choose from the list of available rules:
   Configuration options:
 
   - ``importsOrder`` (``array``, ``null``): defines the order of import types; defaults
-    to ``NULL``
+    to ``null``
   - ``sortAlgorithm`` (``'alpha'``, ``'length'``): whether the statements should be
     sorted alphabetically or by length; defaults to ``'alpha'``
 
@@ -643,7 +647,7 @@ Choose from the list of available rules:
   PHPUnit assertion method calls like "->assertSame(true, $foo)" should be
   written with dedicated method like "->assertTrue($foo)".
 
-  *Risky rule.*
+  *Risky rule: fixer could be risky if one is overriding PHPUnit's native methods.*
 
   Configuration options:
 
@@ -655,7 +659,7 @@ Choose from the list of available rules:
   PHPUnit assertions like "assertInternalType", "assertFileExists", should
   be used over "assertTrue".
 
-  *Risky rule.*
+  *Risky rule: fixer could be risky if one is overriding PHPUnit's native methods.*
 
   Configuration options:
 
@@ -675,7 +679,7 @@ Choose from the list of available rules:
   PHPUnit methods like ``assertSame`` should be used instead of
   ``assertEquals``.
 
-  *Risky rule.*
+  *Risky rule: risky when any of the functions are overridden.*
 
   Configuration options:
 
@@ -794,7 +798,7 @@ Choose from the list of available rules:
 
   Converts ``pow()`` to the ``**`` operator. Requires PHP >= 5.6.
 
-  *Risky rule.*
+  *Risky rule: risky when the function ``pow()`` is overridden.*
 
 * **pre_increment** [@Symfony]
 
@@ -809,7 +813,7 @@ Choose from the list of available rules:
   Classes must be in a path that matches their namespace, be at least one
   namespace deep and the class name should match the file name.
 
-  *Risky rule.*
+  *Risky rule: this fixer may change your class name, which will break the code that is depended on old name.*
 
   Configuration options:
 
@@ -819,14 +823,14 @@ Choose from the list of available rules:
 
   Class names should match the file name.
 
-  *Risky rule.*
+  *Risky rule: this fixer may change you class name, which will break the code that is depended on old name.*
 
 * **random_api_migration** [@PHP70Migration, @PHP71Migration]
 
   Replaces ``rand``, ``mt_rand``, ``srand``, ``getrandmax`` functions calls with
   their ``mt_*`` analogs.
 
-  *Risky rule.*
+  *Risky rule: risky when the configured functions are overridden.*
 
   Configuration options:
 
@@ -862,13 +866,13 @@ Choose from the list of available rules:
 
   Ensures deprecation notices are silenced.
 
-  *Risky rule.*
+  *Risky rule: silencing of deprecation errors might cause changes to code behaviour.*
 
 * **simplified_null_return**
 
   A return statement wishing to return ``void`` should not return ``null``.
 
-  *Risky rule.*
+  *Risky rule: risky since PHP 7.1 as ``null`` and ``void`` can be hinted as return type and have different meaning.*
 
 * **single_blank_line_at_eof** [@PSR2, @Symfony]
 
@@ -914,13 +918,13 @@ Choose from the list of available rules:
 
   Comparisons should be strict.
 
-  *Risky rule.*
+  *Risky rule: changing comparisons to strict might change code behavior.*
 
 * **strict_param**
 
   Functions should be used with ``$strict`` param set to ``true``.
 
-  *Risky rule.*
+  *Risky rule: risky when the fixed function is overridden or if the code relies on non-strict usage.*
 
 * **switch_case_semicolon_to_colon** [@PSR2, @Symfony]
 

+ 34 - 0
src/AbstractFixer.php

@@ -19,6 +19,7 @@ use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
 use PhpCsFixer\Fixer\DefinedFixerInterface;
 use PhpCsFixer\Fixer\FixerInterface;
 use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
+use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
 use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
 use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
 
@@ -39,6 +40,11 @@ abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
      */
     protected $whitespacesConfig;
 
+    /**
+     * @var FixerConfigurationResolverInterface|null
+     */
+    private $configurationDefinition;
+
     public function __construct()
     {
         if ($this instanceof ConfigurableFixerInterface) {
@@ -123,6 +129,22 @@ abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
         }
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function getConfigurationDefinition()
+    {
+        if (!$this instanceof ConfigurationDefinitionFixerInterface) {
+            throw new \LogicException('Cannot get configuration definition using Abstact parent, child not implementing "PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface".');
+        }
+
+        if (null === $this->configurationDefinition) {
+            $this->configurationDefinition = $this->createConfigurationDefinition();
+        }
+
+        return $this->configurationDefinition;
+    }
+
     public function setWhitespacesConfig(WhitespacesFixerConfig $config)
     {
         if (!$this instanceof WhitespacesAwareFixerInterface) {
@@ -132,6 +154,18 @@ abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
         $this->whitespacesConfig = $config;
     }
 
+    /**
+     * @return FixerConfigurationResolverInterface
+     */
+    protected function createConfigurationDefinition()
+    {
+        if (!$this instanceof ConfigurationDefinitionFixerInterface) {
+            throw new \LogicException('Cannot create configuration definition using Abstact parent, child not implementing "PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface".');
+        }
+
+        throw new \LogicException('Not implemented.');
+    }
+
     private function getDefaultWhitespacesFixerConfig()
     {
         static $defaultWhitespacesFixerConfig = null;

+ 16 - 4
src/Console/Command/CommandHelp.php

@@ -260,14 +260,16 @@ EOF
                 array('', ' ', '[$1]', '[', ']', ''),
             );
 
-            return preg_replace(
+            $str = preg_replace(
                 $replaces[0],
                 $replaces[1],
                 var_export($value, true)
             );
+        } else {
+            $str = var_export($value, true);
         }
 
-        return var_export($value, true);
+        return preg_replace('/\bNULL\b/', 'null', $str);
     }
 
     /**
@@ -286,7 +288,12 @@ EOF
                 return !is_callable($value);
             });
 
-            sort($allowed);
+            usort($allowed, function ($valueA, $valueB) {
+                return strcasecmp(
+                    CommandHelp::toString($valueA),
+                    CommandHelp::toString($valueB)
+                );
+            });
 
             if (0 === count($allowed)) {
                 $allowed = null;
@@ -347,7 +354,10 @@ EOF
             }
 
             if ($fixer->isRisky()) {
-                $help .= "   | *Risky rule.*\n";
+                $help .= sprintf(
+                    "   | *Risky rule: %s.*\n",
+                    str_replace('`', '``', lcfirst(preg_replace('/\.$/', '', $fixer->getDefinition()->getRiskyDescription())))
+                );
             }
 
             if ($fixer instanceof ConfigurationDefinitionFixerInterface) {
@@ -404,6 +414,8 @@ EOF
     }
 
     /**
+     * Wraps a string to the given number of characters, ignoring style tags.
+     *
      * @param string $string
      * @param int    $width
      *

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

@@ -219,7 +219,7 @@ EOF;
         $help = preg_replace('#^ \* ``(.+)``(.*?\n)#m', "* **$1**$2\n", $help);
         $help = preg_replace('#^   \\| #m', '  ', $help);
         $help = preg_replace('#^   \\|#m', '', $help);
-        $help = preg_replace('#^(?=  \\*Risky rule.\\*$)#m', "\n", $help);
+        $help = preg_replace('#^(?=  \\*Risky rule: )#m', "\n", $help);
         $help = preg_replace("#^(  Configuration options:\n)(  - )#m", "$1\n$2", $help);
         $help = preg_replace("#^\n( +\\$ )#m", "\n.. code-block:: bash\n\n$1", $help);
         $help = preg_replace("#^\n( +<\\?php)#m", "\n.. code-block:: php\n\n$1", $help);

+ 1 - 1
src/Fixer/Alias/MbStrFunctionsFixer.php

@@ -95,7 +95,7 @@ $a = substr_count($a, $b);
                 ),
             ),
             null,
-            'Risky when the any of functions are overridden.'
+            'Risky when any of the functions are overridden.'
         );
     }
 

+ 16 - 17
src/Fixer/Alias/NoMixedEchoPrintFixer.php

@@ -15,7 +15,7 @@ namespace PhpCsFixer\Fixer\Alias;
 use PhpCsFixer\AbstractFixer;
 use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
 use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
-use PhpCsFixer\FixerConfiguration\FixerOption;
+use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
 use PhpCsFixer\FixerDefinition\CodeSample;
 use PhpCsFixer\FixerDefinition\FixerDefinition;
 use PhpCsFixer\Tokenizer\CT;
@@ -58,22 +58,6 @@ final class NoMixedEchoPrintFixer extends AbstractFixer implements Configuration
         }
     }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getConfigurationDefinition()
-    {
-        $use = new FixerOption('use', 'The desired language construct.');
-        $use
-            ->setAllowedValues(array('print', 'echo'))
-            ->setDefault('echo')
-        ;
-
-        return new FixerConfigurationResolver(array(
-            $use,
-        ));
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -118,6 +102,21 @@ final class NoMixedEchoPrintFixer extends AbstractFixer implements Configuration
         return $tokens->isTokenKindFound($this->candidateTokenType);
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    protected function createConfigurationDefinition()
+    {
+        $use = new FixerOptionBuilder('use', 'The desired language construct.');
+        $use = $use
+            ->setAllowedValues(array('print', 'echo'))
+            ->setDefault('echo')
+            ->getOption()
+        ;
+
+        return new FixerConfigurationResolver(array($use));
+    }
+
     /**
      * @param Tokens $tokens
      * @param int    $index

+ 43 - 44
src/Fixer/Alias/RandomApiMigrationFixer.php

@@ -15,7 +15,7 @@ namespace PhpCsFixer\Fixer\Alias;
 use PhpCsFixer\AbstractFunctionReferenceFixer;
 use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
 use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
-use PhpCsFixer\FixerConfiguration\FixerOption;
+use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
 use PhpCsFixer\FixerDefinition\CodeSample;
 use PhpCsFixer\FixerDefinition\FixerDefinition;
 use PhpCsFixer\Tokenizer\Tokens;
@@ -51,49 +51,6 @@ final class RandomApiMigrationFixer extends AbstractFunctionReferenceFixer imple
         }
     }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getConfigurationDefinition()
-    {
-        $argumentCounts = self::$argumentCounts;
-
-        $replacements = new FixerOption('replacements', 'Mapping between replaced functions with the new ones.');
-        $replacements
-            ->setAllowedTypes(array('array'))
-            ->setAllowedValues(array(function ($value) use ($argumentCounts) {
-                foreach ($value as $functionName => $replacement) {
-                    if (!array_key_exists($functionName, $argumentCounts)) {
-                        throw new InvalidOptionsException(sprintf(
-                            'Function "%s" is not handled by the fixer.',
-                            $functionName
-                        ));
-                    }
-
-                    if (!is_string($replacement)) {
-                        throw new InvalidOptionsException(sprintf(
-                            'Replacement for function "%s" must be a string, "%s" given.',
-                            $functionName,
-                            is_object($replacement) ? get_class($replacement) : gettype($replacement)
-                        ));
-                    }
-                }
-
-                return true;
-            }))
-            ->setDefault(array(
-                'getrandmax' => 'mt_getrandmax',
-                'mt_rand' => 'mt_rand',
-                'rand' => 'mt_rand',
-                'srand' => 'mt_srand',
-            ))
-        ;
-
-        return new FixerConfigurationResolverRootless('replacements', array(
-            $replacements,
-        ));
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -153,4 +110,46 @@ final class RandomApiMigrationFixer extends AbstractFunctionReferenceFixer imple
     {
         return $tokens->isTokenKindFound(T_STRING);
     }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function createConfigurationDefinition()
+    {
+        $argumentCounts = self::$argumentCounts;
+
+        $replacements = new FixerOptionBuilder('replacements', 'Mapping between replaced functions with the new ones.');
+        $replacements = $replacements
+            ->setAllowedTypes(array('array'))
+            ->setAllowedValues(array(function ($value) use ($argumentCounts) {
+                foreach ($value as $functionName => $replacement) {
+                    if (!array_key_exists($functionName, $argumentCounts)) {
+                        throw new InvalidOptionsException(sprintf(
+                            'Function "%s" is not handled by the fixer.',
+                            $functionName
+                        ));
+                    }
+
+                    if (!is_string($replacement)) {
+                        throw new InvalidOptionsException(sprintf(
+                            'Replacement for function "%s" must be a string, "%s" given.',
+                            $functionName,
+                            is_object($replacement) ? get_class($replacement) : gettype($replacement)
+                        ));
+                    }
+                }
+
+                return true;
+            }))
+            ->setDefault(array(
+                'getrandmax' => 'mt_getrandmax',
+                'mt_rand' => 'mt_rand',
+                'rand' => 'mt_rand',
+                'srand' => 'mt_srand',
+            ))
+            ->getOption()
+        ;
+
+        return new FixerConfigurationResolverRootless('replacements', array($replacements));
+    }
 }

+ 26 - 27
src/Fixer/ArrayNotation/ArraySyntaxFixer.php

@@ -15,7 +15,7 @@ namespace PhpCsFixer\Fixer\ArrayNotation;
 use PhpCsFixer\AbstractFixer;
 use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
 use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
-use PhpCsFixer\FixerConfiguration\FixerOption;
+use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
 use PhpCsFixer\FixerDefinition\CodeSample;
 use PhpCsFixer\FixerDefinition\FixerDefinition;
 use PhpCsFixer\FixerDefinition\VersionSpecification;
@@ -48,32 +48,6 @@ final class ArraySyntaxFixer extends AbstractFixer implements ConfigurationDefin
         $this->resolveFixCallback();
     }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getConfigurationDefinition()
-    {
-        $syntax = new FixerOption('syntax', 'Whether to use the `long` or `short` array syntax.');
-        $syntax
-            ->setAllowedValues(array('long', 'short'))
-            ->setNormalizer(function (Options $options, $value) {
-                if (PHP_VERSION_ID < 50400 && 'short' === $value) {
-                    throw new InvalidOptionsException(sprintf(
-                        'Short array syntax is supported from PHP5.4 (your PHP version is %d).',
-                        PHP_VERSION_ID
-                    ));
-                }
-
-                return $value;
-            })
-            ->setDefault('long')
-        ;
-
-        return new FixerConfigurationResolver(array(
-            $syntax,
-        ));
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -125,6 +99,31 @@ final class ArraySyntaxFixer extends AbstractFixer implements ConfigurationDefin
         return $tokens->isTokenKindFound($this->candidateTokenKind);
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    protected function createConfigurationDefinition()
+    {
+        $syntax = new FixerOptionBuilder('syntax', 'Whether to use the `long` or `short` array syntax.');
+        $syntax = $syntax
+            ->setAllowedValues(array('long', 'short'))
+            ->setNormalizer(function (Options $options, $value) {
+                if (PHP_VERSION_ID < 50400 && 'short' === $value) {
+                    throw new InvalidOptionsException(sprintf(
+                        'Short array syntax is supported from PHP5.4 (your PHP version is %d).',
+                        PHP_VERSION_ID
+                    ));
+                }
+
+                return $value;
+            })
+            ->setDefault('long')
+            ->getOption()
+        ;
+
+        return new FixerConfigurationResolver(array($syntax));
+    }
+
     /**
      * @param Tokens $tokens
      * @param int    $index

+ 16 - 17
src/Fixer/Basic/BracesFixer.php

@@ -16,7 +16,7 @@ use PhpCsFixer\AbstractFixer;
 use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
 use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
 use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
-use PhpCsFixer\FixerConfiguration\FixerOption;
+use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
 use PhpCsFixer\FixerDefinition\CodeSample;
 use PhpCsFixer\FixerDefinition\FixerDefinition;
 use PhpCsFixer\Tokenizer\CT;
@@ -31,22 +31,6 @@ use PhpCsFixer\Tokenizer\TokensAnalyzer;
  */
 final class BracesFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
 {
-    /**
-     * {@inheritdoc}
-     */
-    public function getConfigurationDefinition()
-    {
-        $allowSingleLineClosure = new FixerOption('allow_single_line_closure', 'Whether single line lambda notation should be allowed.');
-        $allowSingleLineClosure
-            ->setAllowedTypes(array('bool'))
-            ->setDefault(false)
-        ;
-
-        return new FixerConfigurationResolver(array(
-            $allowSingleLineClosure,
-        ));
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -125,6 +109,21 @@ $negative = function ($item) {
         return true;
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    protected function createConfigurationDefinition()
+    {
+        $allowSingleLineClosure = new FixerOptionBuilder('allow_single_line_closure', 'Whether single line lambda notation should be allowed.');
+        $allowSingleLineClosure = $allowSingleLineClosure
+            ->setAllowedTypes(array('bool'))
+            ->setDefault(false)
+            ->getOption()
+        ;
+
+        return new FixerConfigurationResolver(array($allowSingleLineClosure));
+    }
+
     private function fixCommentBeforeBrace(Tokens $tokens)
     {
         $tokensAnalyzer = new TokensAnalyzer($tokens);

+ 16 - 15
src/Fixer/Basic/Psr0Fixer.php

@@ -15,7 +15,7 @@ namespace PhpCsFixer\Fixer\Basic;
 use PhpCsFixer\AbstractPsrAutoloadingFixer;
 use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
 use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
-use PhpCsFixer\FixerConfiguration\FixerOption;
+use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
 use PhpCsFixer\FixerDefinition\FileSpecificCodeSample;
 use PhpCsFixer\FixerDefinition\FixerDefinition;
 use PhpCsFixer\Tokenizer\Tokens;
@@ -28,19 +28,6 @@ use PhpCsFixer\Tokenizer\Tokens;
  */
 final class Psr0Fixer extends AbstractPsrAutoloadingFixer implements ConfigurationDefinitionFixerInterface
 {
-    /**
-     * {@inheritdoc}
-     */
-    public function getConfigurationDefinition()
-    {
-        $dir = new FixerOption('dir', 'The directory where the project code is placed.');
-        $dir->setAllowedTypes(array('string'));
-
-        return new FixerConfigurationResolver(array(
-            $dir,
-        ));
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -159,7 +146,21 @@ class InvalidName {}
                 ),
             ),
             null,
-            'This fixer may change you class name, which will break the code that is depended on old name.'
+            'This fixer may change your class name, which will break the code that is depended on old name.'
         );
     }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function createConfigurationDefinition()
+    {
+        $dir = new FixerOptionBuilder('dir', 'The directory where the project code is placed.');
+        $dir = $dir
+            ->setAllowedTypes(array('string'))
+            ->getOption()
+        ;
+
+        return new FixerConfigurationResolver(array($dir));
+    }
 }

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