Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FixCommand - forbid passing 'config' and 'rules' options together #3387

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions src/Console/Command/FixCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use PhpCsFixer\Config;
use PhpCsFixer\ConfigInterface;
use PhpCsFixer\ConfigurationException\InvalidConfigurationException;
use PhpCsFixer\Console\ConfigurationResolver;
use PhpCsFixer\Console\Output\ErrorOutput;
use PhpCsFixer\Console\Output\NullOutput;
Expand Down Expand Up @@ -121,11 +122,13 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$verbosity = $output->getVerbosity();

$passedConfig = $input->getOption('config');
$passedRules = $input->getOption('rules');

if (null !== $passedConfig && null !== $passedRules) {
throw new InvalidConfigurationException('Passing both `--config` and `--rules` options is not allowed.');
}

$resolver = new ConfigurationResolver(
$this->defaultConfig,
[
Expand All @@ -141,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'diff' => $input->getOption('diff'),
'diff-format' => $input->getOption('diff-format'),
'stop-on-violation' => $input->getOption('stop-on-violation'),
'verbosity' => $verbosity,
'verbosity' => $output->getVerbosity(),
'show-progress' => $input->getOption('show-progress'),
],
getcwd(),
Expand All @@ -156,17 +159,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
;

if (null !== $stdErr) {
if (null !== $passedConfig && null !== $passedRules) {
if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
throw new \RuntimeException('Passing both `config` and `rules` options is not possible. This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.');
}

$stdErr->writeln([
sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', 'When passing both "--config" and "--rules" the rules within the configuration file are not used.'),
sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', 'Passing both options is deprecated; version v3.0 PHP-CS-Fixer will exit with a configuration error code.'),
]);
}

$configFile = $resolver->getConfigFile();
$stdErr->writeln(sprintf('Loaded config <comment>%s</comment>%s.', $resolver->getConfig()->getName(), null === $configFile ? '' : ' from "'.$configFile.'"'));

Expand Down