Refactor rector rules to simplify code and fix rule definition

This commit is contained in:
Julien Fastré 2024-02-18 23:06:54 +01:00
parent bb4b7e9735
commit d135b2ba0a
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 22 additions and 12 deletions

View File

@ -12,13 +12,14 @@ declare(strict_types=1);
namespace Chill\Utils\Rector\Rector; namespace Chill\Utils\Rector\Rector;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest; use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Chill\Utils\Rector\Tests\ChillBundleMakeDataProviderStaticForAbstractFilterTest\ChillBundleMakeDataProviderStaticForAbstractFilterTestTest; use Chill\Utils\Rector\Tests\ChillBundleMakeDataProviderStaticForAbstractFilterTest\ChillBundleMakeDataProviderStaticForAbstractFilterTestRectorTest;
use PhpParser\Node; use PhpParser\Node;
use Rector\Rector\AbstractRector; use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/** /**
* @see ChillBundleMakeDataProviderStaticForAbstractFilterTestTest * @see ChillBundleMakeDataProviderStaticForAbstractFilterTestRectorTest
*/ */
final class ChillBundleMakeDataProviderStaticForAbstractAggregatorTestRector extends AbstractRector final class ChillBundleMakeDataProviderStaticForAbstractAggregatorTestRector extends AbstractRector
{ {
@ -26,7 +27,9 @@ final class ChillBundleMakeDataProviderStaticForAbstractAggregatorTestRector ext
{ {
return new RuleDefinition( return new RuleDefinition(
'Make static each method which provide data on AbstractAggregatorTest', 'Make static each method which provide data on AbstractAggregatorTest',
[''] [
new CodeSample('', ''),
]
); );
} }
@ -70,7 +73,6 @@ final class ChillBundleMakeDataProviderStaticForAbstractAggregatorTestRector ext
$method->returnType = match ($stmt->name->name) { $method->returnType = match ($stmt->name->name) {
'getFormData' => new Node\Identifier('array'), 'getFormData' => new Node\Identifier('array'),
'getQueryBuilders' => new Node\Identifier('iterable'), 'getQueryBuilders' => new Node\Identifier('iterable'),
default => throw new \UnexpectedValueException('this name is not supported: '.$stmt->name->name)
}; };
foreach ($stmt->getStmts() as $s) { foreach ($stmt->getStmts() as $s) {

View File

@ -12,13 +12,18 @@ declare(strict_types=1);
namespace Chill\Utils\Rector\Rector; namespace Chill\Utils\Rector\Rector;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\Utils\Rector\Tests\ChillBundleMakeDataProviderStaticForAbstractFilterTest\ChillBundleMakeDataProviderStaticForAbstractFilterTestTest; use Chill\Utils\Rector\Tests\ChillBundleMakeDataProviderStaticForAbstractExportTestRectorTest\ChillBundleMakeDataProviderStaticForAbstractExportTestRectorTest;
use PhpParser\Node; use PhpParser\Node;
use Rector\Rector\AbstractRector; use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/** /**
* @see ChillBundleMakeDataProviderStaticForAbstractFilterTestTest * Class ChillBundleMakeDataProviderStaticForAbstractExportTestRector.
*
* This class is responsible for making each method that provides data on AbstractExportTest static.
*
* @see ChillBundleMakeDataProviderStaticForAbstractExportTestRectorTest for testing
*/ */
final class ChillBundleMakeDataProviderStaticForAbstractExportTestRector extends AbstractRector final class ChillBundleMakeDataProviderStaticForAbstractExportTestRector extends AbstractRector
{ {
@ -26,7 +31,9 @@ final class ChillBundleMakeDataProviderStaticForAbstractExportTestRector extends
{ {
return new RuleDefinition( return new RuleDefinition(
'Make static each method which provide data on AbstractExportTest', 'Make static each method which provide data on AbstractExportTest',
[''] [
new CodeSample('', ''),
]
); );
} }
@ -70,7 +77,6 @@ final class ChillBundleMakeDataProviderStaticForAbstractExportTestRector extends
$method->returnType = match ($stmt->name->name) { $method->returnType = match ($stmt->name->name) {
'getFormData' => new Node\Identifier('array'), 'getFormData' => new Node\Identifier('array'),
'getModifiersCombination' => new Node\Identifier('array'), 'getModifiersCombination' => new Node\Identifier('array'),
default => throw new \UnexpectedValueException('this name is not supported: '.$stmt->name->name)
}; };
foreach ($stmt->getStmts() as $s) { foreach ($stmt->getStmts() as $s) {

View File

@ -12,13 +12,14 @@ declare(strict_types=1);
namespace Chill\Utils\Rector\Rector; namespace Chill\Utils\Rector\Rector;
use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\MainBundle\Test\Export\AbstractFilterTest;
use Chill\Utils\Rector\Tests\ChillBundleMakeDataProviderStaticForAbstractFilterTest\ChillBundleMakeDataProviderStaticForAbstractFilterTestTest; use Chill\Utils\Rector\Tests\ChillBundleMakeDataProviderStaticForAbstractFilterTest\ChillBundleMakeDataProviderStaticForAbstractFilterTestRectorTest;
use PhpParser\Node; use PhpParser\Node;
use Rector\Rector\AbstractRector; use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/** /**
* @see ChillBundleMakeDataProviderStaticForAbstractFilterTestTest * @see ChillBundleMakeDataProviderStaticForAbstractFilterTestRectorTest
*/ */
final class ChillBundleMakeDataProviderStaticForAbstractFilterTestRector extends AbstractRector final class ChillBundleMakeDataProviderStaticForAbstractFilterTestRector extends AbstractRector
{ {
@ -26,7 +27,9 @@ final class ChillBundleMakeDataProviderStaticForAbstractFilterTestRector extends
{ {
return new RuleDefinition( return new RuleDefinition(
'Make static each method which provide data', 'Make static each method which provide data',
[''] [
new CodeSample('', ''),
]
); );
} }
@ -70,7 +73,6 @@ final class ChillBundleMakeDataProviderStaticForAbstractFilterTestRector extends
$method->returnType = match ($stmt->name->name) { $method->returnType = match ($stmt->name->name) {
'getFormData' => new Node\Identifier('array'), 'getFormData' => new Node\Identifier('array'),
'getQueryBuilders' => new Node\Identifier('iterable'), 'getQueryBuilders' => new Node\Identifier('iterable'),
default => throw new \UnexpectedValueException('this name is not supported: '.$stmt->name->name)
}; };
foreach ($stmt->getStmts() as $s) { foreach ($stmt->getStmts() as $s) {