Skip to content

Commit

Permalink
move from SETS parameter to explicit include
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 6, 2021
1 parent 812ff5b commit cff4bc6
Show file tree
Hide file tree
Showing 258 changed files with 798 additions and 623 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,14 @@ And modify it:

```php
// rector.php
use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// here we can define, what sets of rules will be applied
$parameters = $containerConfigurator->parameters();

// tip: use "SetList" class to autocomplete sets
$parameters->set(Option::SETS, [SetList::CODE_QUALITY]);
$containerConfigurator->import(SetList::CODE_QUALITY);

// register single rule
$services = $containerConfigurator->services();
Expand Down
12 changes: 5 additions & 7 deletions build/config/config-downgrade-php70.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/phpstan-for-downgrade.neon');

$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
DowngradeSetList::PHP_73,
DowngradeSetList::PHP_72,
DowngradeSetList::PHP_71,
]);
$containerConfigurator->import(DowngradeSetList::PHP_80);
$containerConfigurator->import(DowngradeSetList::PHP_74);
$containerConfigurator->import(DowngradeSetList::PHP_73);
$containerConfigurator->import(DowngradeSetList::PHP_72);
$containerConfigurator->import(DowngradeSetList::PHP_71);
};

/**
Expand Down
10 changes: 4 additions & 6 deletions build/config/config-downgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@

$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/phpstan-for-downgrade.neon');

$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
DowngradeSetList::PHP_73,
DowngradeSetList::PHP_72,
]);
$containerConfigurator->import(DowngradeSetList::PHP_80);
$containerConfigurator->import(DowngradeSetList::PHP_74);
$containerConfigurator->import(DowngradeSetList::PHP_73);
$containerConfigurator->import(DowngradeSetList::PHP_72);
};

/**
Expand Down
3 changes: 1 addition & 2 deletions docs/init_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura

return static function (ContainerConfigurator $containerConfigurator): void {
// here we can define, what sets of rules will be applied
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SETS, [SetList::CODE_QUALITY]);
$containerConfigurator->import(SetList::CODE_QUALITY);

// register single rule
$services = $containerConfigurator->services();
Expand Down
5 changes: 4 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
__DIR__ . '/config/set',
]);

$parameters->set(Option::SETS, [SetList::PSR_12, SetList::SYMPLIFY, SetList::COMMON, SetList::CLEAN_CODE]);
$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::SYMPLIFY);
$containerConfigurator->import(SetList::COMMON);
$containerConfigurator->import(SetList::CLEAN_CODE);

$parameters->set(Option::SKIP, [
'*/Source/*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public function enterNode(Node $node): ?Node
}

$variadicAwareParamTagValueNode = new VariadicAwareParamTagValueNode(
$node->type, $node->isVariadic, $node->parameterName, $node->description
$node->type,
$node->isVariadic,
$node->parameterName,
$node->description
);

$this->attributeMirrorer->mirror($node, $variadicAwareParamTagValueNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function parse(TokenIterator $tokenIterator): PhpDocNode
$children[] = $this->parseChildAndStoreItsPositions($tokenIterator);

while ($tokenIterator->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL) && ! $tokenIterator->isCurrentTokenType(
Lexer::TOKEN_CLOSE_PHPDOC
)) {
Lexer::TOKEN_CLOSE_PHPDOC
)) {
$children[] = $this->parseChildAndStoreItsPositions($tokenIterator);
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/Caching/Config/FileHashComputer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ private function ensureIsPhp(SmartFileInfo $fileInfo): void

throw new ShouldNotHappenException(sprintf(
// getRealPath() cannot be used, as it breaks in phar
'Provide only PHP file, ready for Symfony Dependency Injection. "%s" given', $fileInfo->getRelativeFilePath()
'Provide only PHP file, ready for Symfony Dependency Injection. "%s" given',
$fileInfo->getRelativeFilePath()
));
}

Expand Down
14 changes: 8 additions & 6 deletions packages/PostRector/Rector/NodeAddingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ public function leaveNode(Node $node)

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Add nodes on weird positions', [
new CodeSample(
<<<'CODE_SAMPLE'
return new RuleDefinition(
'Add nodes on weird positions',
[
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
Expand All @@ -76,8 +78,8 @@ public function run($value)
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
,
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($value)
Expand All @@ -88,7 +90,7 @@ public function run($value)
}
}
CODE_SAMPLE
), ]
), ]
);
}
}
8 changes: 5 additions & 3 deletions packages/PostRector/Rector/NodeRemovingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ public function leaveNode(Node $node)

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Remove nodes from weird positions', [
new CodeSample(
return new RuleDefinition(
'Remove nodes from weird positions',
[
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
Expand All @@ -122,7 +124,7 @@ public function run($value)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
10 changes: 6 additions & 4 deletions packages/PostRector/Rector/NodeToReplacePostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public function leaveNode(Node $node): ?Node

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Replaces nodes on weird positions', [
new CodeSample(
return new RuleDefinition(
'Replaces nodes on weird positions',
[
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
Expand All @@ -50,7 +52,7 @@ public function run($value)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand All @@ -60,7 +62,7 @@ public function run($value)
}
}
CODE_SAMPLE
), ]
), ]
);
}
}
8 changes: 5 additions & 3 deletions packages/PostRector/Rector/PropertyAddingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public function enterNode(Node $node): ?Node

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Add dependency properties', [
new CodeSample(
return new RuleDefinition(
'Add dependency properties',
[
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
Expand All @@ -91,7 +93,7 @@ public function run()
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
class SomeClass
{
Expand Down
8 changes: 5 additions & 3 deletions packages/PostRector/Rector/UseAddingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ public function getPriority(): int

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Add unique use imports collected during Rector run', [
new CodeSample(
return new RuleDefinition(
'Add unique use imports collected during Rector run',
[
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
Expand All @@ -137,7 +139,7 @@ public function run(AnotherClass $anotherClass)
}
}
CODE_SAMPLE
,
,
<<<'CODE_SAMPLE'
use App\AnotherClass;
Expand Down
33 changes: 16 additions & 17 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

return static function (ContainerConfigurator $containerConfigurator): void {
// include sets
$containerConfigurator->import(SetList::CODING_STYLE);
$containerConfigurator->import(SetList::CODE_QUALITY);
$containerConfigurator->import(SetList::CODE_QUALITY_STRICT);
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PRIVATIZATION);
$containerConfigurator->import(SetList::NAMING);
$containerConfigurator->import(SetList::TYPE_DECLARATION);
$containerConfigurator->import(SetList::PHP_71);
$containerConfigurator->import(SetList::PHP_72);
$containerConfigurator->import(SetList::PHP_73);
$containerConfigurator->import(SetList::EARLY_RETURN);
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
$containerConfigurator->import(NetteSetList::NETTE_UTILS_CODE_QUALITY);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);

$services = $containerConfigurator->services();

$configuration = ValueObjectInliner::inline([
Expand All @@ -42,23 +58,6 @@

$parameters = $containerConfigurator->parameters();

$parameters->set(Option::SETS, [
SetList::CODING_STYLE,
SetList::CODE_QUALITY,
SetList::CODE_QUALITY_STRICT,
SetList::DEAD_CODE,
SetList::PRIVATIZATION,
SetList::NAMING,
SetList::TYPE_DECLARATION,
SetList::PHP_71,
SetList::PHP_72,
SetList::PHP_73,
SetList::EARLY_RETURN,
SetList::TYPE_DECLARATION_STRICT,
NetteSetList::NETTE_UTILS_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
]);

$parameters->set(Option::PATHS, [
__DIR__ . '/src',
__DIR__ . '/rules',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
$services = $containerConfigurator->services();
$services->set(SwapFuncCallArgumentsRector::class)
->call('configure', [[
SwapFuncCallArgumentsRector::FUNCTION_ARGUMENT_SWAPS => ValueObjectInliner::inline([

new SwapFuncCallArguments('some_function', [1, 0]),
]
SwapFuncCallArgumentsRector::FUNCTION_ARGUMENT_SWAPS => ValueObjectInliner::inline(
[new SwapFuncCallArguments('some_function', [1, 0])]
),
]]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
$services = $containerConfigurator->services();
$services->set(NormalToFluentRector::class)
->call('configure', [[
NormalToFluentRector::CALLS_TO_FLUENT => ValueObjectInliner::inline([
NormalToFluentRector::CALLS_TO_FLUENT => ValueObjectInliner::inline(
[

new NormalToFluent(FluentInterfaceClass::class, ['someFunction', 'otherFunction', 'joinThisAsWell']),
]
new NormalToFluent(FluentInterfaceClass::class, [
'someFunction',
'otherFunction',
'joinThisAsWell',
]),
]
),
]]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(CompleteImportForPartialAnnotationRector::class)
->call('configure', [[
CompleteImportForPartialAnnotationRector::USE_IMPORTS_TO_RESTORE => ValueObjectInliner::inline([
new CompleteImportForPartialAnnotation('Doctrine\ORM\Mapping', 'ORM'),
]),
]]
);
->call(
'configure',
[[
CompleteImportForPartialAnnotationRector::USE_IMPORTS_TO_RESTORE => ValueObjectInliner::inline([
new CompleteImportForPartialAnnotation('Doctrine\ORM\Mapping', 'ORM'),
]),
]]
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
$services = $containerConfigurator->services();
$services->set(PropertyFetchToMethodCallRector::class)
->call('configure', [[
PropertyFetchToMethodCallRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
PropertyFetchToMethodCallRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline(
[

new PropertyFetchToMethodCall(Translator::class, 'locale', 'getLocale', 'setLocale'),
new PropertyFetchToMethodCall(
'Rector\Tests\Transform\Rector\Assign\PropertyFetchToMethodCallRector\Fixture\Fixture2',
'parameter',
'getConfig',
null,
['parameter']),
]
new PropertyFetchToMethodCall(Translator::class, 'locale', 'getLocale', 'setLocale'),
new PropertyFetchToMethodCall(
'Rector\Tests\Transform\Rector\Assign\PropertyFetchToMethodCallRector\Fixture\Fixture2',
'parameter',
'getConfig',
null,
['parameter']
),
]
),
]]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
NetteServiceDefinition::class,
'setInject',
'addTag',
['inject']),
['inject']
),
]);

$services->set(MethodCallToAnotherMethodCallWithArgumentsRector::class)
Expand Down
Loading

0 comments on commit cff4bc6

Please sign in to comment.