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

Fixed bug with applying risky changes #93

Merged
merged 1 commit into from Aug 28, 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
19 changes: 19 additions & 0 deletions rules/7.2-risky.php
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;

require __DIR__ . '/main.php';

$rules['@PHP70Migration'] = true;
$rules['@PHP70Migration:risky'] = true;
$rules['@PHP71Migration'] = true;
$rules['@PHP71Migration:risky'] = true;
$rules['@PSR12:risky'] = true;

return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
1 change: 0 additions & 1 deletion rules/7.2.php
Expand Up @@ -12,5 +12,4 @@
return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
20 changes: 20 additions & 0 deletions rules/7.3-risky.php
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;

require __DIR__ . '/main.php';

$rules['@PHP70Migration'] = true;
$rules['@PHP70Migration:risky'] = true;
$rules['@PHP71Migration'] = true;
$rules['@PHP71Migration:risky'] = true;
$rules['@PHP73Migration'] = true;
$rules['@PSR12:risky'] = true;

return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
1 change: 0 additions & 1 deletion rules/7.3.php
Expand Up @@ -13,5 +13,4 @@
return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
22 changes: 22 additions & 0 deletions rules/7.4-risky.php
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;

require __DIR__ . '/main.php';

$rules['@PHP70Migration'] = true;
$rules['@PHP70Migration:risky'] = true;
$rules['@PHP71Migration'] = true;
$rules['@PHP71Migration:risky'] = true;
$rules['@PHP73Migration'] = true;
$rules['@PHP74Migration'] = true;
$rules['@PHP74Migration:risky'] = true;
$rules['@PSR12:risky'] = true;

return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
1 change: 0 additions & 1 deletion rules/7.4.php
Expand Up @@ -14,5 +14,4 @@
return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
24 changes: 24 additions & 0 deletions rules/8.0-risky.php
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;

require __DIR__ . '/main.php';

$rules['@PHP70Migration'] = true;
$rules['@PHP70Migration:risky'] = true;
$rules['@PHP71Migration'] = true;
$rules['@PHP71Migration:risky'] = true;
$rules['@PHP73Migration'] = true;
$rules['@PHP74Migration'] = true;
$rules['@PHP74Migration:risky'] = true;
$rules['@PHP80Migration'] = true;
$rules['@PHP80Migration:risky'] = true;
$rules['@PSR12:risky'] = true;

return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
1 change: 0 additions & 1 deletion rules/8.0.php
Expand Up @@ -15,5 +15,4 @@
return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
21 changes: 21 additions & 0 deletions rules/8.1-risky.php
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;

require __DIR__ . '/main.php';

$rules['@PHP70Migration'] = true;
$rules['@PHP71Migration'] = true;
$rules['@PHP73Migration'] = true;
$rules['@PHP74Migration'] = true;
$rules['@PHP80Migration'] = true;
$rules['@PHP81Migration'] = true;
$rules['@PSR12:risky'] = true;

return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
1 change: 0 additions & 1 deletion rules/8.1.php
Expand Up @@ -16,5 +16,4 @@
return (new Config())
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules($rules);
6 changes: 3 additions & 3 deletions src/Commands/Check.php
Expand Up @@ -14,11 +14,11 @@ class Check extends BaseCommand

protected string $status = 'Checking code-style...';

protected function configure()
protected function configure(): void
{
$this
->setName('check')
->setDescription('Checking the codestyle of the project')
->addOption('risky', null, InputOption::VALUE_OPTIONAL, 'Allows to set whether risky rules may run', 'no');
->setDescription('Checking the code-style of the project')
->addOption('risky', null, InputOption::VALUE_NONE, 'Allows to set whether risky rules may run');
}
}
2 changes: 1 addition & 1 deletion src/Commands/Dependabot.php
Expand Up @@ -13,7 +13,7 @@ class Dependabot extends BaseCommand

protected string $status = 'Updating Dependabot rules...';

protected function configure()
protected function configure(): void
{
$this
->setName('dependabot')
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/EditorConfig.php
Expand Up @@ -13,7 +13,7 @@ class EditorConfig extends BaseCommand

protected string $status = 'Updating .editorconfig...';

protected function configure()
protected function configure(): void
{
$this
->setName('editorconfig')
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Fix.php
Expand Up @@ -14,11 +14,11 @@ class Fix extends BaseCommand

protected string $status = 'Checking and fixing the code-style...';

protected function configure()
protected function configure(): void
{
$this
->setName('fix')
->setDescription('Fix the codestyle of the project')
->addOption('risky', null, InputOption::VALUE_OPTIONAL, 'Allows to set whether risky rules may run');
->setDescription('Fix the code-style of the project')
->addOption('risky', null, InputOption::VALUE_NONE, 'Allows to set whether risky rules may run');
}
}
11 changes: 9 additions & 2 deletions src/Processors/CodeStyler.php
Expand Up @@ -75,7 +75,7 @@ protected function getDecorationOption(): array

protected function getRiskyOption(): array
{
return $this->input->hasOption('risky') && $this->input->getOption('risky') !== 'no'
return $this->hasRisky()
? ['--allow-risky' => 'yes']
: ['--allow-risky' => 'no'];
}
Expand All @@ -84,7 +84,9 @@ protected function getConfigFilename(): string
{
$path = __DIR__ . '/../../rules/';

$config = $path . $this->getPhpVersion() . '.php';
$risky = $this->hasRisky() ? '-risky' : '';

$config = $path . $this->getPhpVersion() . $risky . '.php';

return file_exists($config) ? $config : $path . PhpVersion::DEFAULT . '.php';
}
Expand All @@ -93,4 +95,9 @@ protected function getPhpVersion(): string
{
return PhpVersion::make()->get();
}

protected function hasRisky(): bool
{
return $this->input->hasOption('risky') && $this->input->getOption('risky');
}
}
2 changes: 2 additions & 0 deletions tests/Fixtures/Support/PhpVersion.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Support;

use DragonCode\CodeStyler\Support\PhpVersion as BasePhpVersion;
Expand Down
22 changes: 12 additions & 10 deletions tests/Support/PhpVersionTest.php
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

namespace Tests\Support;

use Tests\Fixtures\Support\PhpVersion;
use Tests\TestCase;

class PhpVersionTest extends TestCase
{
public function test72()
public function test72(): void
{
$helper = PhpVersion::make()->setComposer([
'require' => [
Expand All @@ -20,7 +22,7 @@ public function test72()
$this->assertSame('7.2', $helper);
}

public function test72Dev()
public function test72Dev(): void
{
$helper = PhpVersion::make()->setComposer([
'require-dev' => [
Expand All @@ -33,7 +35,7 @@ public function test72Dev()
$this->assertSame('7.2', $helper);
}

public function test74()
public function test74(): void
{
$helper = PhpVersion::make()->setComposer([
'require' => [
Expand All @@ -46,7 +48,7 @@ public function test74()
$this->assertSame('7.4', $helper);
}

public function test74Dev()
public function test74Dev(): void
{
$helper = PhpVersion::make()->setComposer([
'require-dev' => [
Expand All @@ -59,7 +61,7 @@ public function test74Dev()
$this->assertSame('7.4', $helper);
}

public function test80()
public function test80(): void
{
$helper = PhpVersion::make()->setComposer([
'require' => [
Expand All @@ -72,7 +74,7 @@ public function test80()
$this->assertSame('8.0', $helper);
}

public function test80Dev()
public function test80Dev(): void
{
$helper = PhpVersion::make()->setComposer([
'require-dev' => [
Expand All @@ -85,7 +87,7 @@ public function test80Dev()
$this->assertSame('8.0', $helper);
}

public function test81()
public function test81(): void
{
$helper = PhpVersion::make()->setComposer([
'require' => [
Expand All @@ -98,7 +100,7 @@ public function test81()
$this->assertSame('8.1', $helper);
}

public function test81Dev()
public function test81Dev(): void
{
$helper = PhpVersion::make()->setComposer([
'require-dev' => [
Expand All @@ -111,7 +113,7 @@ public function test81Dev()
$this->assertSame('8.1', $helper);
}

public function testDefault()
public function testDefault(): void
{
$helper = PhpVersion::make()->setComposer([
'require' => [
Expand All @@ -123,7 +125,7 @@ public function testDefault()
$this->assertSame('8.1', $helper);
}

public function testDefaultDev()
public function testDefaultDev(): void
{
$helper = PhpVersion::make()->setComposer([
'require-dev' => [
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests;

use PHPUnit\Framework\TestCase as BaseTestCase;
Expand Down