forked from rectorphp/rector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rector-recipe.php.dist
82 lines (62 loc) · 2.46 KB
/
rector-recipe.php.dist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types=1);
use PhpParser\Node\Expr\MethodCall;
use Rector\RectorGenerator\Provider\RectorRecipeProvider;
use Rector\RectorGenerator\ValueObject\RectorRecipe;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Rector\SymfonyPhpConfig\inline_single_object;
// run "bin/rector generate" to a new Rector basic schema + tests from this config
return static function (ContainerConfigurator $containerConfigurator): void {
// [REQUIRED]
$rectorRecipe = new RectorRecipe(
// name, basically short class name; use PascalCase
'RenameMethodCallRector',
// particular node types to change
// the best practise is to have just 1 type here if possible, and make separated rule for other node types
[MethodCall::class],
// describe what the rule does
'"something()" will be renamed to "somethingElse()"',
// code before change
// this is used for documentation and first test fixture
<<<'CODE_SAMPLE'
<?php
class SomeClass
{
public function run()
{
$this->something();
}
}
CODE_SAMPLE
// code after change
, <<<'CODE_SAMPLE'
<?php
class SomeClass
{
public function run()
{
$this->somethingElse();
}
}
CODE_SAMPLE
);
// [OPTIONAL - UNCOMMENT TO USE]
// links to useful websites, that explain why the change is needed
// $rectorRecipe->setResources([
// 'https://github.com/symfony/symfony/blob/704c648ba53be38ef2b0105c97c6497744fef8d8/UPGRADE-6.0.md'
// ]);
// do you need to check for extra generated file?
// $rectorRecipe->addExtraFile('SomeExtraFile.php', '<?php ... SomeExtraFileContent');
// is the rule configurable? add default configuration here
// $rectorRecipe->addConfiguration(['SOME_CONSTANT_KEY' => ['before' => 'after']]);
// [RECTOR CORE CONTRIBUTION]
// [RECTOR CORE CONTRIBUTION - REQUIRED]
// package name, basically part namespace in `rule/<package>/src`, use PascalCase
// $rectorRecipe->setPackage('Generic');
// [RECTOR CORE CONTRIBUTION - OPTIONAL]
// set the rule belongs to; is optional, because e.g. generic rules don't need a specific set to belong to
// $rectorRecipe->setSet(\Rector\Set\ValueObject\SetList::NAMING);
$services = $containerConfigurator->services();
$services->set(RectorRecipeProvider::class)
->arg('$rectorRecipe', inline_single_object($rectorRecipe, $services));
};