diff --git a/README.md b/README.md index f197fea..b59d291 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,17 @@ codestyle editorconfig codestyle dependabot ``` +### Options + +#### Risky + +Allows to set whether risky rules may run: + +```bash +codestyle check --risky +codestyle fix --risky +``` + ### GitHub Action #### Check diff --git a/composer.json b/composer.json index c08a8fe..16579d8 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "symfony/yaml": "^6.0" }, "require-dev": { - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "symfony/var-dumper": "^6.1" }, "minimum-stability": "stable", "autoload": { diff --git a/src/Commands/BaseCommand.php b/src/Commands/BaseCommand.php index 812e85e..f5fdd65 100644 --- a/src/Commands/BaseCommand.php +++ b/src/Commands/BaseCommand.php @@ -59,6 +59,6 @@ protected function handle(): void protected function resolveProcessor(): Processor { - return new $this->processor($this->output); + return new $this->processor($this->input, $this->output); } } diff --git a/src/Commands/Check.php b/src/Commands/Check.php index 17d7a9d..5d72ff6 100644 --- a/src/Commands/Check.php +++ b/src/Commands/Check.php @@ -6,6 +6,7 @@ use DragonCode\CodeStyler\Contracts\Processor; use DragonCode\CodeStyler\Processors\Check as CheckProcessor; +use Symfony\Component\Console\Input\InputOption; class Check extends BaseCommand { @@ -17,6 +18,7 @@ protected function configure() { $this ->setName('check') - ->setDescription('Checking the codestyle of the project'); + ->setDescription('Checking the codestyle of the project') + ->addOption('risky', null, InputOption::VALUE_OPTIONAL, 'Allows to set whether risky rules may run', 'no'); } } diff --git a/src/Commands/Fix.php b/src/Commands/Fix.php index 731d76a..83d3a89 100644 --- a/src/Commands/Fix.php +++ b/src/Commands/Fix.php @@ -6,6 +6,7 @@ use DragonCode\CodeStyler\Contracts\Processor; use DragonCode\CodeStyler\Processors\Fix as FixProcessor; +use Symfony\Component\Console\Input\InputOption; class Fix extends BaseCommand { @@ -17,6 +18,7 @@ protected function configure() { $this ->setName('fix') - ->setDescription('Fix the codestyle of the project'); + ->setDescription('Fix the codestyle of the project') + ->addOption('risky', null, InputOption::VALUE_OPTIONAL, 'Allows to set whether risky rules may run'); } } diff --git a/src/Contracts/Processor.php b/src/Contracts/Processor.php index a903610..120d196 100644 --- a/src/Contracts/Processor.php +++ b/src/Contracts/Processor.php @@ -4,11 +4,12 @@ namespace DragonCode\CodeStyler\Contracts; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; interface Processor { - public function __construct(OutputInterface $output); + public function __construct(InputInterface $input, OutputInterface $output); public function run(): void; } diff --git a/src/Processors/BaseProcessor.php b/src/Processors/BaseProcessor.php index 5530122..64b3a2f 100644 --- a/src/Processors/BaseProcessor.php +++ b/src/Processors/BaseProcessor.php @@ -5,11 +5,13 @@ namespace DragonCode\CodeStyler\Processors; use DragonCode\CodeStyler\Contracts\Processor; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; abstract class BaseProcessor implements Processor { public function __construct( + protected InputInterface $input, protected OutputInterface $output ) { } diff --git a/src/Processors/CodeStyler.php b/src/Processors/CodeStyler.php index 664ff1c..503bd69 100644 --- a/src/Processors/CodeStyler.php +++ b/src/Processors/CodeStyler.php @@ -64,7 +64,7 @@ protected function getOptions(): array { return array_merge($this->options, $this->options_check, [ '--config' => $this->getConfigFilename(), - ], $this->getDecorationOption()); + ], $this->getDecorationOption(), $this->getRiskyOption()); } protected function getDecorationOption(): array @@ -74,6 +74,13 @@ protected function getDecorationOption(): array : ['--no-ansi' => true]; } + protected function getRiskyOption(): array + { + return $this->input->hasOption('risky') && $this->input->getOption('risky') !== 'no' + ? ['--allow-risky' => 'yes'] + : ['--allow-risky' => 'no']; + } + protected function getConfigFilename(): string { $path = __DIR__ . '/../../rules/';