Skip to content

Commit

Permalink
minor #5601 Always stop when "PHP_CS_FIXER_FUTURE_MODE" is used (kuba…
Browse files Browse the repository at this point in the history
…werlos)

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](053c5d5) 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](64ca575) 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
-------

86ccb06 Always stop when "PHP_CS_FIXER_FUTURE_MODE" is used
  • Loading branch information
keradus committed Apr 9, 2021
2 parents 082a84b + 86ccb06 commit 063a142
Show file tree
Hide file tree
Showing 23 changed files with 164 additions and 124 deletions.
32 changes: 13 additions & 19 deletions src/AbstractFixer.php
Expand Up @@ -118,13 +118,10 @@ public function configure(array $configuration = null)
}

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 = [];
}
Expand All @@ -136,19 +133,16 @@ public function configure(array $configuration = null)

$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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Expand Up @@ -46,7 +46,7 @@ public function __construct($name = 'default')
*/
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();
}
Expand Down
30 changes: 9 additions & 21 deletions src/Console/ConfigurationResolver.php
Expand Up @@ -446,13 +446,10 @@ public function getProgress()
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;
Expand Down Expand Up @@ -786,13 +783,7 @@ private function validateRules(array $rules)
? 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}");
}
}
}
Expand Down Expand Up @@ -938,13 +929,10 @@ private function resolveOptionBooleanValue($optionName)
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php
Expand Up @@ -24,6 +24,7 @@
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;

Expand Down Expand Up @@ -193,8 +194,7 @@ protected function createConfigurationDefinition()
->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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php
Expand Up @@ -26,6 +26,7 @@
use PhpCsFixer\Tokenizer\CT;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Utils;
use Symfony\Component\OptionsResolver\Options;

/**
Expand All @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/Operator/AlignDoubleArrowFixerHelper.php
Expand Up @@ -16,6 +16,7 @@
use PhpCsFixer\Tokenizer\CT;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Utils;

/**
* @author Carlos Cirello <carlos.cirello.nl@gmail.com>
Expand All @@ -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
)
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/Operator/AlignEqualsFixerHelper.php
Expand Up @@ -16,6 +16,7 @@
use PhpCsFixer\Tokenizer\CT;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Utils;

/**
* @author Carlos Cirello <carlos.cirello.nl@gmail.com>
Expand All @@ -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
)
);
}

Expand Down
18 changes: 8 additions & 10 deletions src/Fixer/Operator/BinaryOperatorSpacesFixer.php
Expand Up @@ -25,6 +25,7 @@
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Tokenizer\TokensAnalyzer;
use PhpCsFixer\Utils;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;

/**
Expand Down Expand Up @@ -554,18 +555,15 @@ private function resolveOldConfig(array $configuration)
}
}

$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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php
Expand Up @@ -23,6 +23,7 @@
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Tokenizer\TokensAnalyzer;
use PhpCsFixer\Utils;

/**
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
Expand Down Expand Up @@ -88,7 +89,7 @@ public function configure(array $configuration = null)

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];
Expand Down
12 changes: 5 additions & 7 deletions src/Fixer/Whitespace/NoExtraBlankLinesFixer.php
Expand Up @@ -26,6 +26,7 @@
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Tokenizer\TokensAnalyzer;
use PhpCsFixer\Utils;
use Symfony\Component\OptionsResolver\Options;

/**
Expand Down Expand Up @@ -319,13 +320,10 @@ protected function createConfigurationDefinition()
->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;
Expand Down
3 changes: 2 additions & 1 deletion src/FixerConfiguration/FixerConfigurationResolver.php
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\FixerConfiguration;

use PhpCsFixer\Utils;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand Down Expand Up @@ -67,7 +68,7 @@ public function resolve(array $options)
throw new InvalidOptionsException(sprintf('Aliased option "%s"/"%s" is passed multiple times.', $name, $alias));
}

@trigger_error(sprintf('Option "%s" is deprecated, use "%s" instead.', $alias, $name), E_USER_DEPRECATED);
Utils::triggerDeprecation(sprintf('Option "%s" is deprecated, use "%s" instead.', $alias, $name));

$options[$name] = $options[$alias];
unset($options[$alias]);
Expand Down
10 changes: 3 additions & 7 deletions src/FixerConfiguration/FixerConfigurationResolverRootless.php
Expand Up @@ -12,6 +12,8 @@

namespace PhpCsFixer\FixerConfiguration;

use PhpCsFixer\Utils;

/**
* @internal
*
Expand Down Expand Up @@ -82,13 +84,7 @@ static function (FixerOptionInterface $option) {
$passedNames = array_keys($options);

if (!empty(array_diff($passedNames, $names))) {
$message = "Passing \"{$this->root}\" at the root of the configuration for rule \"{$this->fixerName}\" is deprecated and will not be supported in 3.0, use \"{$this->root}\" => array(...) option instead.";

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("Passing \"{$this->root}\" at the root of the configuration for rule \"{$this->fixerName}\" is deprecated and will not be supported in 3.0, use \"{$this->root}\" => array(...) option instead.");

$options = [$this->root => $options];
}
Expand Down
10 changes: 6 additions & 4 deletions src/FixerDefinition/FixerDefinition.php
Expand Up @@ -12,6 +12,8 @@

namespace PhpCsFixer\FixerDefinition;

use PhpCsFixer\Utils;

/**
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
*/
Expand Down Expand Up @@ -41,9 +43,9 @@ public function __construct(
$riskyDescription = null
) {
if (6 === \func_num_args()) {
@trigger_error('Arguments #5 and #6 of FixerDefinition::__construct() are deprecated and will be removed in 3.0, use argument #4 instead.', E_USER_DEPRECATED);
Utils::triggerDeprecation('Arguments #5 and #6 of FixerDefinition::__construct() are deprecated and will be removed in 3.0, use argument #4 instead.');
} elseif (5 === \func_num_args()) {
@trigger_error('Argument #5 of FixerDefinition::__construct() is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
Utils::triggerDeprecation('Argument #5 of FixerDefinition::__construct() is deprecated and will be removed in 3.0.');
} else {
$riskyDescription = $configurationDescription;
$configurationDescription = null;
Expand All @@ -69,14 +71,14 @@ public function getDescription()

public function getConfigurationDescription()
{
@trigger_error(sprintf('%s is deprecated and will be removed in 3.0.', __METHOD__), E_USER_DEPRECATED);
Utils::triggerDeprecation(sprintf('%s is deprecated and will be removed in 3.0.', __METHOD__));

return $this->configurationDescription;
}

public function getDefaultConfiguration()
{
@trigger_error(sprintf('%s is deprecated and will be removed in 3.0.', __METHOD__), E_USER_DEPRECATED);
Utils::triggerDeprecation(sprintf('%s is deprecated and will be removed in 3.0.', __METHOD__));

return $this->defaultConfiguration;
}
Expand Down
15 changes: 7 additions & 8 deletions src/RuleSet/RuleSet.php
Expand Up @@ -13,6 +13,7 @@
namespace PhpCsFixer\RuleSet;

use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
use PhpCsFixer\Utils;

/**
* Set of rules to be used by fixer.
Expand Down Expand Up @@ -51,12 +52,10 @@ public function __construct(array $set = [])
if (true !== $value && false !== $value && !\is_array($value)) {
// @TODO drop me on 3.0
if (null === $value) {
$messageForNullIssue = 'To disable the rule, use "FALSE" instead of "NULL".';
if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
throw new InvalidFixerConfigurationException($name, $messageForNullIssue);
}

@trigger_error($messageForNullIssue, E_USER_DEPRECATED);
Utils::triggerDeprecation(
'To disable the rule, use "FALSE" instead of "NULL".',
InvalidFixerConfigurationException::class
);

continue;
}
Expand Down Expand Up @@ -107,7 +106,7 @@ public function getRules()
*/
public static function create(array $set = [])
{
@trigger_error(__METHOD__.' is deprecated and will be removed in 3.0, use the constructor.', E_USER_DEPRECATED);
Utils::triggerDeprecation(__METHOD__.' is deprecated and will be removed in 3.0, use the constructor.');

return new self($set);
}
Expand All @@ -117,7 +116,7 @@ public static function create(array $set = [])
*/
public function getSetDefinitionNames()
{
@trigger_error(__METHOD__.' is deprecated and will be removed in 3.0, use PhpCsFixer\RuleSet\RuleSets::getSetDefinitionNames.', E_USER_DEPRECATED);
Utils::triggerDeprecation(__METHOD__.' is deprecated and will be removed in 3.0, use PhpCsFixer\RuleSet\RuleSets::getSetDefinitionNames.');

return RuleSets::getSetDefinitionNames();
}
Expand Down

0 comments on commit 063a142

Please sign in to comment.