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

Added --risky option #90

Merged
merged 1 commit into from Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/BaseCommand.php
Expand Up @@ -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);
}
}
4 changes: 3 additions & 1 deletion src/Commands/Check.php
Expand Up @@ -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
{
Expand All @@ -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');
}
}
4 changes: 3 additions & 1 deletion src/Commands/Fix.php
Expand Up @@ -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
{
Expand All @@ -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');
}
}
3 changes: 2 additions & 1 deletion src/Contracts/Processor.php
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/Processors/BaseProcessor.php
Expand Up @@ -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
) {
}
Expand Down
9 changes: 8 additions & 1 deletion src/Processors/CodeStyler.php
Expand Up @@ -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
Expand All @@ -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/';
Expand Down