Browse Source

Fix transforming deprecations into exceptions

Julien Falque 3 years ago
parent
commit
6f74ce3694

+ 10 - 14
src/AbstractFixer.php

@@ -118,10 +118,9 @@ abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
         }
 
         if (null === $configuration) {
-            Utils::triggerDeprecation(
-                'Passing NULL to set default configuration is deprecated and will not be supported in 3.0, use an empty array instead.',
-                \InvalidArgumentException::class
-            );
+            Utils::triggerDeprecation(new \InvalidArgumentException(
+                'Passing NULL to set default configuration is deprecated and will not be supported in 3.0, use an empty array instead.'
+            ));
 
             $configuration = [];
         }
@@ -133,16 +132,13 @@ abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
 
             $name = $option->getName();
             if (\array_key_exists($name, $configuration)) {
-                Utils::triggerDeprecation(
-                    sprintf(
-                        'Option "%s" for rule "%s" is deprecated and will be removed in version %d.0. %s',
-                        $name,
-                        $this->getName(),
-                        Application::getMajorVersion() + 1,
-                        str_replace('`', '"', $option->getDeprecationMessage())
-                    ),
-                    \InvalidArgumentException::class
-                );
+                Utils::triggerDeprecation(new \InvalidArgumentException(sprintf(
+                    'Option "%s" for rule "%s" is deprecated and will be removed in version %d.0. %s',
+                    $name,
+                    $this->getName(),
+                    Application::getMajorVersion() + 1,
+                    str_replace('`', '"', $option->getDeprecationMessage())
+                )));
             }
         }
 

+ 1 - 1
src/Config.php

@@ -46,7 +46,7 @@ class Config implements ConfigInterface
      */
     public static function create()
     {
-        Utils::triggerDeprecation(__METHOD__.' is deprecated since 2.17 and will be removed in 3.0.');
+        Utils::triggerDeprecation(new \RuntimeException(__METHOD__.' is deprecated since 2.17 and will be removed in 3.0.'));
 
         return new static();
     }

+ 8 - 10
src/Console/ConfigurationResolver.php

@@ -235,7 +235,7 @@ final class ConfigurationResolver
 
                 if (isset($deprecatedConfigs[$configFileBasename])) {
                     $message = "Configuration file `{$configFileBasename}` is deprecated, rename to `{$deprecatedConfigs[$configFileBasename]}`.";
-                    Utils::triggerDeprecation($message, InvalidConfigurationException::class);
+                    Utils::triggerDeprecation(new InvalidConfigurationException($message));
                 }
 
                 $config = self::separatedContextLessInclude($configFile);
@@ -457,10 +457,9 @@ final class ConfigurationResolver
                         implode('", "', $progressTypes)
                     ));
                 } elseif (\in_array($progressType, ['estimating', 'estimating-max', 'run-in'], true)) {
-                    Utils::triggerDeprecation(
-                        'Passing `estimating`, `estimating-max` or `run-in` is deprecated and will not be supported in 3.0, use `none` or `dots` instead.',
-                        \InvalidArgumentException::class
-                    );
+                    Utils::triggerDeprecation(new \InvalidArgumentException(
+                        'Passing `estimating`, `estimating-max` or `run-in` is deprecated and will not be supported in 3.0, use `none` or `dots` instead.'
+                    ));
                 }
 
                 $this->progress = $progressType;
@@ -798,7 +797,7 @@ final class ConfigurationResolver
                     ? sprintf(' and will be removed in version %d.0.', Application::getMajorVersion() + 1)
                     : sprintf('. Use %s instead.', str_replace('`', '"', Utils::naturalLanguageJoinWithBackticks($successors)));
 
-                Utils::triggerDeprecation("Rule \"{$fixerName}\" is deprecated{$messageEnd}");
+                Utils::triggerDeprecation(new \RuntimeException("Rule \"{$fixerName}\" is deprecated{$messageEnd}"));
             }
         }
     }
@@ -944,10 +943,9 @@ final class ConfigurationResolver
             return false;
         }
 
-        Utils::triggerDeprecation(
-            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),
-            InvalidConfigurationException::class
-        );
+        Utils::triggerDeprecation(new InvalidConfigurationException(
+            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)
+        ));
 
         return false;
     }

+ 3 - 1
src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php

@@ -194,7 +194,9 @@ class Sample
                 ->setNormalizer(static function (Options $options, $values) {
                     $deprecated = array_intersect($values, self::SUPPORTED_TYPES);
                     if (\count($deprecated) > 0) {
-                        Utils::triggerDeprecation('A list of elements is deprecated, use a dictionary of `const|method|property` => `none|one` instead.');
+                        Utils::triggerDeprecation(new \RuntimeException(
+                            'A list of elements is deprecated, use a dictionary of `const|method|property` => `none|one` instead.'
+                        ));
 
                         return array_fill_keys($deprecated, self::SPACING_ONE);
                     }

+ 1 - 1
src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php

@@ -43,7 +43,7 @@ final class MethodArgumentSpaceFixer extends AbstractFixer implements Configurat
      */
     public function fixSpace(Tokens $tokens, $index)
     {
-        Utils::triggerDeprecation(__METHOD__.' is deprecated and will be removed in 3.0.');
+        Utils::triggerDeprecation(new \RuntimeException(__METHOD__.' is deprecated and will be removed in 3.0.'));
         $this->fixSpace2($tokens, $index);
     }
 

+ 4 - 6
src/Fixer/Operator/AlignDoubleArrowFixerHelper.php

@@ -38,12 +38,10 @@ final class AlignDoubleArrowFixerHelper extends AbstractAlignFixerHelper
 
     public function __construct()
     {
-        Utils::triggerDeprecation(
-            sprintf(
-                'The "%s" class is deprecated. You should stop using it, as it will be removed in 3.0 version.',
-                __CLASS__
-            )
-        );
+        Utils::triggerDeprecation(new \RuntimeException(sprintf(
+            'The "%s" class is deprecated. You should stop using it, as it will be removed in 3.0 version.',
+            __CLASS__
+        )));
     }
 
     /**

+ 4 - 6
src/Fixer/Operator/AlignEqualsFixerHelper.php

@@ -28,12 +28,10 @@ final class AlignEqualsFixerHelper extends AbstractAlignFixerHelper
 {
     public function __construct()
     {
-        Utils::triggerDeprecation(
-            sprintf(
-                'The "%s" class is deprecated. You should stop using it, as it will be removed in 3.0 version.',
-                __CLASS__
-            )
-        );
+        Utils::triggerDeprecation(new \RuntimeException(sprintf(
+            'The "%s" class is deprecated. You should stop using it, as it will be removed in 3.0 version.',
+            __CLASS__
+        )));
     }
 
     /**

+ 4 - 4
src/Fixer/Operator/BinaryOperatorSpacesFixer.php

@@ -555,14 +555,14 @@ $array = [
             }
         }
 
-        Utils::triggerDeprecation(
+        Utils::triggerDeprecation(new InvalidFixerConfigurationException(
+            $this->getName(),
             sprintf(
                 'Given configuration is deprecated and will be removed in 3.0. Use configuration %s as replacement for %s.',
                 HelpCommand::toString($newConfig),
                 HelpCommand::toString($configuration)
-            ),
-            InvalidFixerConfigurationException::class
-        );
+            )
+        ));
 
         return $newConfig;
     }

+ 1 - 1
src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php

@@ -89,7 +89,7 @@ final class BlankLineBeforeStatementFixer extends AbstractFixer implements Confi
 
         foreach ($this->configuration['statements'] as $key) {
             if ('die' === $key) {
-                Utils::triggerDeprecation('Option "die" is deprecated, use "exit" instead.');
+                Utils::triggerDeprecation(new \RuntimeException('Option "die" is deprecated, use "exit" instead.'));
             }
 
             $this->fixTokenMap[$key] = self::$tokenMap[$key];

+ 3 - 4
src/Fixer/Whitespace/NoExtraBlankLinesFixer.php

@@ -320,10 +320,9 @@ switch($a) {
                 ->setNormalizer(static function (Options $options, $tokens) use ($that) {
                     foreach ($tokens as &$token) {
                         if ('useTrait' === $token) {
-                            Utils::triggerDeprecation(
-                                "Token \"useTrait\" in option \"tokens\" for rule \"{$that->getName()}\" is deprecated and will be removed in 3.0, use \"use_trait\" instead.",
-                                InvalidConfigurationException::class
-                            );
+                            Utils::triggerDeprecation(new InvalidConfigurationException(
+                                "Token \"useTrait\" in option \"tokens\" for rule \"{$that->getName()}\" is deprecated and will be removed in 3.0, use \"use_trait\" instead."
+                            ));
                             $token = 'use_trait';
 
                             break;

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