Skip to content

Commit

Permalink
Merge pull request #90 from TheDragonCode/2.x
Browse files Browse the repository at this point in the history
Added `--risky` option
  • Loading branch information
andrey-helldar committed Aug 26, 2022
2 parents f8b3ad6 + 68c2d71 commit c88e29b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 6 deletions.
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 @@ -63,7 +63,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 @@ -73,6 +73,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

0 comments on commit c88e29b

Please sign in to comment.