Browse Source

minor #5601 Always stop when "PHP_CS_FIXER_FUTURE_MODE" is used (kubawerlos)

This PR was merged into the 2.19-dev branch.

Discussion
----------

Always stop when "PHP_CS_FIXER_FUTURE_MODE" is used

Deprecations are not always stopping application when `PHP_CS_FIXER_FUTURE_MODE` is on.

We can see that in [first commit](https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5601/commits/053c5d530895aab89cfabce55ee2aa26d7b75fcf) where rules with deprecation configuration was added the build have passed - and we run fixer with `PHP_CS_FIXER_FUTURE_MODE` flag: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.18.5/.github/workflows/ci.yml#L146

The [second commit](https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5601/commits/64ca575114174557961070a8531d9978e392ef62) is moving all `trigger_error` calls to `Utils::triggerDeprecation` and there we decide basing on `PHP_CS_FIXER_FUTURE_MODE` if throw an exception.

3rd and 4th commits are restoring config and makes fabbot happy, respectively.

Commits
-------

86ccb0674 Always stop when "PHP_CS_FIXER_FUTURE_MODE" is used
Dariusz Ruminski 3 years ago
parent
commit
063a142754

+ 13 - 19
src/AbstractFixer.php

@@ -118,13 +118,10 @@ abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
         }
 
         if (null === $configuration) {
-            $message = 'Passing NULL to set default configuration is deprecated and will not be supported in 3.0, use an empty array instead.';
-
-            if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
-                throw new \InvalidArgumentException("{$message} This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.");
-            }
-
-            @trigger_error($message, E_USER_DEPRECATED);
+            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
+            );
 
             $configuration = [];
         }
@@ -136,19 +133,16 @@ abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
 
             $name = $option->getName();
             if (\array_key_exists($name, $configuration)) {
-                $message = 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())
+                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
                 );
-
-                if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
-                    throw new \InvalidArgumentException("{$message} This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.");
-                }
-
-                @trigger_error($message, E_USER_DEPRECATED);
             }
         }
 

+ 1 - 1
src/Config.php

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

+ 9 - 21
src/Console/ConfigurationResolver.php

@@ -446,13 +446,10 @@ final class ConfigurationResolver
                         implode('", "', $progressTypes)
                     ));
                 } elseif (\in_array($progressType, ['estimating', 'estimating-max', 'run-in'], true)) {
-                    $message = 'Passing `estimating`, `estimating-max` or `run-in` is deprecated and will not be supported in 3.0, use `none` or `dots` instead.';
-
-                    if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
-                        throw new \InvalidArgumentException("{$message} This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.");
-                    }
-
-                    @trigger_error($message, E_USER_DEPRECATED);
+                    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
+                    );
                 }
 
                 $this->progress = $progressType;
@@ -786,13 +783,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)));
 
-                $message = "Rule \"{$fixerName}\" is deprecated{$messageEnd}";
-
-                if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
-                    throw new \RuntimeException("{$message} This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.");
-                }
-
-                @trigger_error($message, E_USER_DEPRECATED);
+                Utils::triggerDeprecation("Rule \"{$fixerName}\" is deprecated{$messageEnd}");
             }
         }
     }
@@ -938,13 +929,10 @@ 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);
+        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
+        );
 
         return false;
     }

+ 2 - 2
src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php

@@ -24,6 +24,7 @@ use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 use PhpCsFixer\Tokenizer\TokensAnalyzer;
+use PhpCsFixer\Utils;
 use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
 use Symfony\Component\OptionsResolver\Options;
 
@@ -193,8 +194,7 @@ class Sample
                 ->setNormalizer(static function (Options $options, $values) {
                     $deprecated = array_intersect($values, self::SUPPORTED_TYPES);
                     if (\count($deprecated) > 0) {
-                        $message = 'A list of elements is deprecated, use a dictionary of `const|method|property` => `none|one` instead.';
-                        @trigger_error($message, E_USER_DEPRECATED);
+                        Utils::triggerDeprecation('A list of elements is deprecated, use a dictionary of `const|method|property` => `none|one` instead.');
 
                         return array_fill_keys($deprecated, self::SPACING_ONE);
                     }

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

@@ -26,6 +26,7 @@ use PhpCsFixer\Preg;
 use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
+use PhpCsFixer\Utils;
 use Symfony\Component\OptionsResolver\Options;
 
 /**
@@ -42,7 +43,7 @@ final class MethodArgumentSpaceFixer extends AbstractFixer implements Configurat
      */
     public function fixSpace(Tokens $tokens, $index)
     {
-        @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
+        Utils::triggerDeprecation(__METHOD__.' is deprecated and will be removed in 3.0.');
         $this->fixSpace2($tokens, $index);
     }
 

+ 3 - 3
src/Fixer/Operator/AlignDoubleArrowFixerHelper.php

@@ -16,6 +16,7 @@ use PhpCsFixer\AbstractAlignFixerHelper;
 use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
+use PhpCsFixer\Utils;
 
 /**
  * @author Carlos Cirello <carlos.cirello.nl@gmail.com>
@@ -37,12 +38,11 @@ final class AlignDoubleArrowFixerHelper extends AbstractAlignFixerHelper
 
     public function __construct()
     {
-        @trigger_error(
+        Utils::triggerDeprecation(
             sprintf(
                 'The "%s" class is deprecated. You should stop using it, as it will be removed in 3.0 version.',
                 __CLASS__
-            ),
-            E_USER_DEPRECATED
+            )
         );
     }
 

+ 3 - 3
src/Fixer/Operator/AlignEqualsFixerHelper.php

@@ -16,6 +16,7 @@ use PhpCsFixer\AbstractAlignFixerHelper;
 use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
+use PhpCsFixer\Utils;
 
 /**
  * @author Carlos Cirello <carlos.cirello.nl@gmail.com>
@@ -27,12 +28,11 @@ final class AlignEqualsFixerHelper extends AbstractAlignFixerHelper
 {
     public function __construct()
     {
-        @trigger_error(
+        Utils::triggerDeprecation(
             sprintf(
                 'The "%s" class is deprecated. You should stop using it, as it will be removed in 3.0 version.',
                 __CLASS__
-            ),
-            E_USER_DEPRECATED
+            )
         );
     }
 

+ 8 - 10
src/Fixer/Operator/BinaryOperatorSpacesFixer.php

@@ -25,6 +25,7 @@ use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 use PhpCsFixer\Tokenizer\TokensAnalyzer;
+use PhpCsFixer\Utils;
 use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
 
 /**
@@ -554,18 +555,15 @@ $array = [
             }
         }
 
-        $message = 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)
+        Utils::triggerDeprecation(
+            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
         );
 
-        if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
-            throw new InvalidFixerConfigurationException($this->getName(), "{$message} This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.");
-        }
-
-        @trigger_error($message, E_USER_DEPRECATED);
-
         return $newConfig;
     }
 

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

@@ -23,6 +23,7 @@ use PhpCsFixer\FixerDefinition\FixerDefinition;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 use PhpCsFixer\Tokenizer\TokensAnalyzer;
+use PhpCsFixer\Utils;
 
 /**
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
@@ -88,7 +89,7 @@ final class BlankLineBeforeStatementFixer extends AbstractFixer implements Confi
 
         foreach ($this->configuration['statements'] as $key) {
             if ('die' === $key) {
-                @trigger_error('Option "die" is deprecated, use "exit" instead.', E_USER_DEPRECATED);
+                Utils::triggerDeprecation('Option "die" is deprecated, use "exit" instead.');
             }
 
             $this->fixTokenMap[$key] = self::$tokenMap[$key];

+ 5 - 7
src/Fixer/Whitespace/NoExtraBlankLinesFixer.php

@@ -26,6 +26,7 @@ use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 use PhpCsFixer\Tokenizer\TokensAnalyzer;
+use PhpCsFixer\Utils;
 use Symfony\Component\OptionsResolver\Options;
 
 /**
@@ -319,13 +320,10 @@ switch($a) {
                 ->setNormalizer(static function (Options $options, $tokens) use ($that) {
                     foreach ($tokens as &$token) {
                         if ('useTrait' === $token) {
-                            $message = "Token \"useTrait\" in option \"tokens\" for rule \"{$that->getName()}\" is deprecated and will be removed in 3.0, use \"use_trait\" instead.";
-
-                            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);
+                            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
+                            );
                             $token = 'use_trait';
 
                             break;

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