Skip to content

Commit

Permalink
refactor: add rector rules
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Oct 29, 2019
1 parent f378406 commit 8855261
Show file tree
Hide file tree
Showing 33 changed files with 71 additions and 45 deletions.
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ tests: &tests
run: |
composer test -vvv
bin/doc
vendor/bin/php-cs-fixer fix --diff || (echo "Coding standards are not respected. Run 'vendor/bin/php-cs-fixer fix'" && exit 1)
composer run rector || (echo "Coding standards are not respected. Run 'composer run rector'" && exit 1)
composer run php-cs-fixer || (echo "Coding standards are not respected. Run 'composer run php-cs-fixer'" && exit 1)
tests_with_future_mode: &tests_with_future_mode
run: |
PHP_CS_FIXER_FUTURE_MODE=1 composer test -vvv
bin/doc
vendor/bin/php-cs-fixer fix --diff || (echo "Coding standards are not respected. Run 'vendor/bin/php-cs-fixer fix'" && exit 1)
composer run rector || (echo "Coding standards are not respected. Run 'composer run rector'" && exit 1)
composer run php-cs-fixer || (echo "Coding standards are not respected. Run 'composer run php-cs-fixer'" && exit 1)
jobs:
php 7.1:
Expand Down
19 changes: 16 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
},
"require-dev": {
"phpspec/phpspec": "^5.1.0",
"rector/rector": "^0.5.19",
"twig/twig": "^2.11.3",
"webmozart/assert": "^1.3.0"
},
"autoload": {
"psr-4": { "PedroTroller\\CS\\": "src/PedroTroller/CS/" }
"psr-4": {
"PedroTroller\\CS\\Fixer\\": "src/PedroTroller/CS/Fixer"
}
},
"autoload-dev": {
"psr-4": {
"tests\\": "tests/"
"spec\\": "spec",
"tests\\": "tests"
}
},
"config": {
Expand All @@ -33,8 +37,17 @@
"tests": [
"tests\\Runner::run",
"tests\\Orchestra::run",
"phpspec run -fpretty",
"phpspec run -fpretty"
],
"rector": [
"rector process src/ tests/ spec/"
],
"php-cs-fixer": [
"php-cs-fixer fix --dry-run -vvv --diff"
],
"lint": [
"@rector",
"@php-cs-fixer"
]
}
}
13 changes: 13 additions & 0 deletions rector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
parameters:
auto_import_names: true

exclude_rectors:
- Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector

imports:
- resource: vendor/rector/rector/config/set/code-quality/*
- resource: vendor/rector/rector/config/set/php/php71.yaml
- resource: vendor/rector/rector/config/set/phpspec/*
- resource: vendor/rector/rector/config/set/psr-4/*
- resource: vendor/rector/rector/config/set/solid/*
2 changes: 1 addition & 1 deletion spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PedroTroller\CS\Fixer\RuleSetFactory;
use PhpSpec\ObjectBehavior;

class RuleSetFactorySpec extends ObjectBehavior
final class RuleSetFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
$i = $tokens->getNextTokenOfKind($i, ['{']);
$elements = $this->getElements($tokens, $i);

if (!$elements) {
if ($elements === []) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

final class LineBreakBetweenMethodArgumentsFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
{
const T_TYPEHINT_SEMI_COLON = 10025;
private const T_TYPEHINT_SEMI_COLON = 10025;

/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function fixSpaces($index, Tokens $tokens): void
return;
}

if (false === \in_array($tokens[$nextMeaningful]->getId(), array_keys($this->handlers), true)) {
if (false === \array_key_exists($tokens[$nextMeaningful]->getId(), $this->handlers)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
$whitespaceIndex = null;

do {
$previous = $previous - 1;
--$previous;

if ($tokens[$previous]->isComment()) {
$comments = array_merge(
Expand Down
14 changes: 6 additions & 8 deletions src/PedroTroller/CS/Fixer/Comment/UselessCommentFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,13 @@ private function getUselessComments($index, Tokens $tokens)
foreach ($arguments as $argument) {
if (null === $argument['type']) {
$useless[] = sprintf('/^@param +\%s/', $argument['name']);
} elseif ($argument['nullable']) {
$useless[] = sprintf('/^@param +%s\|null +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
$useless[] = sprintf('/^@param +null\|%s +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
$useless[] = sprintf('/^@param +%s \| null +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
$useless[] = sprintf('/^@param +null \| %s +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
} else {
if ($argument['nullable']) {
$useless[] = sprintf('/^@param +%s\|null +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
$useless[] = sprintf('/^@param +null\|%s +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
$useless[] = sprintf('/^@param +%s \| null +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
$useless[] = sprintf('/^@param +null \| %s +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
} else {
$useless[] = sprintf('/^@param +%s +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
}
$useless[] = sprintf('/^@param +%s +\%s$/', str_replace('\\', '\\\\', $argument['type']), $argument['name']);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/PedroTroller/CS/Fixer/TokenSignatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

final class TokenSignatures
{
const TYPINT_OPTIONAL = 10022;
const TYPINT_DOUBLE_DOTS = 10025;
public const TYPINT_OPTIONAL = 10022;
public const TYPINT_DOUBLE_DOTS = 10025;

public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SplFileInfo;
use Symfony\Component\Finder\Finder;

class Runner
final class Runner
{
public static function run(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TokensAnalyzerIntegration/InSwitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use tests\TokensAnalyzerIntegration;
use Webmozart\Assert\Assert;

class InSwitch extends TokensAnalyzerIntegration
final class InSwitch extends TokensAnalyzerIntegration
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/TokensAnalyzerIntegration/MethodArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use tests\TokensAnalyzerIntegration;
use Webmozart\Assert\Assert;

class MethodArguments extends TokensAnalyzerIntegration
final class MethodArguments extends TokensAnalyzerIntegration
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/TokensAnalyzerIntegration/SizeOfTheLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use tests\TokensAnalyzerIntegration;
use Webmozart\Assert\Assert;

class SizeOfTheLine extends TokensAnalyzerIntegration
final class SizeOfTheLine extends TokensAnalyzerIntegration
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/ForbiddenFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\CodingStyle\ForbiddenFunctionsFixer;
use tests\UseCase;

class ForbiddenFunctions implements UseCase
final class ForbiddenFunctions implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/LineBreakBetweenMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\CodingStyle\LineBreakBetweenMethodArgumentsFixer;
use tests\UseCase;

class LineBreakBetweenMethods implements UseCase
final class LineBreakBetweenMethods implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/LineBreakBetweenMethods/Regression/Case1.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\CodingStyle\LineBreakBetweenMethodArgumentsFixer;
use tests\UseCase;

class Case1 implements UseCase
final class Case1 implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/LineBreakBetweenMethods/Regression/Case2.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\CodingStyle\LineBreakBetweenMethodArgumentsFixer;
use tests\UseCase;

class Case2 implements UseCase
final class Case2 implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/LineBreakBetweenMethods/Regression/Case3.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\CodingStyle\LineBreakBetweenMethodArgumentsFixer;
use tests\UseCase;

class Case3 implements UseCase
final class Case3 implements UseCase
{
/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\CodingStyle\LineBreakBetweenMethodArgumentsFixer;
use tests\UseCase;

class LineBreakBetweenMethodsWithNoReformatting implements UseCase
final class LineBreakBetweenMethodsWithNoReformatting implements UseCase
{
/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\CodingStyle\LineBreakBetweenMethodArgumentsFixer;
use tests\UseCase;

class LineBreakBetweenMethodsWithNoSplitOnNumberOfArgs implements UseCase
final class LineBreakBetweenMethodsWithNoSplitOnNumberOfArgs implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/LineBreakBetweenStatements.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\CodingStyle\LineBreakBetweenStatementsFixer;
use tests\UseCase;

class LineBreakBetweenStatements implements UseCase
final class LineBreakBetweenStatements implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/OrderedSpecElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\Phpspec\OrderedSpecElementsFixer;
use tests\UseCase;

class OrderedSpecElements implements UseCase
final class OrderedSpecElements implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/OrderedSpecElements/Regression/Case1.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\Phpspec\OrderedSpecElementsFixer;
use tests\UseCase;

class Case1 implements UseCase
final class Case1 implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/OrderedWithGetterAndSetterFirst.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\ClassNotation\OrderedWithGetterAndSetterFirstFixer;
use tests\UseCase;

class OrderedWithGetterAndSetterFirst implements UseCase
final class OrderedWithGetterAndSetterFirst implements UseCase
{
/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\ClassNotation\OrderedWithGetterAndSetterFirstFixer;
use tests\UseCase;

class Case1 implements UseCase
final class Case1 implements UseCase
{
/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\ClassNotation\OrderedWithGetterAndSetterFirstFixer;
use tests\UseCase;

class Case2 implements UseCase
final class Case2 implements UseCase
{
/**
* {@inheritdoc}
Expand Down
4 changes: 2 additions & 2 deletions tests/UseCase/Phpspec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace tests\Usecase;
namespace tests\UseCase;

use PedroTroller\CS\Fixer\PhpspecFixer;
use tests\UseCase;

class Phpspec implements UseCase
final class Phpspec implements UseCase
{
/**
* {@inheritdoc}
Expand Down
4 changes: 2 additions & 2 deletions tests/UseCase/PhpspecScenarioScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace tests\Usecase;
namespace tests\UseCase;

use PedroTroller\CS\Fixer\Phpspec\PhpspecScenarioScopeFixer;
use tests\UseCase;

class PhpspecScenarioScope implements UseCase
final class PhpspecScenarioScope implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/UselessCodeAfterReturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\DeadCode\UselessCodeAfterReturnFixer;
use tests\UseCase;

class UselessCodeAfterReturn implements UseCase
final class UselessCodeAfterReturn implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/UselessComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\Comment\UselessCommentFixer;
use tests\UseCase;

class UselessComment implements UseCase
final class UselessComment implements UseCase
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion tests/UseCase/UselessComment/Php71.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\Comment\UselessCommentFixer;
use tests\UseCase;

class Php71 implements UseCase
final class Php71 implements UseCase
{
/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PedroTroller\CS\Fixer\Comment\UselessCommentFixer;
use tests\UseCase;

class DoubleLineBreak implements UseCase
final class DoubleLineBreak implements UseCase
{
/**
* {@inheritdoc}
Expand Down

0 comments on commit 8855261

Please sign in to comment.