-
-
Notifications
You must be signed in to change notification settings - Fork 360
/
RectorConfig.php
146 lines (122 loc) · 3.84 KB
/
RectorConfig.php
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
declare(strict_types=1);
namespace Rector\Config;
use Rector\Core\Configuration\Option;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\ValueObject\PhpVersion;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Webmozart\Assert\Assert;
/**
* @api
* Same as Symfony container configurator, with patched return type for "set()" method for easier DX.
* It is an alias for internal class that is prefixed during build, so it's basically for keeping stable public API.
*/
final class RectorConfig extends ContainerConfigurator
{
/**
* @param string[] $paths
*/
public function paths(array $paths): void
{
Assert::allString($paths);
$parameters = $this->parameters();
$parameters->set(Option::PATHS, $paths);
}
/**
* @param string[] $sets
*/
public function sets(array $sets): void
{
Assert::allString($sets);
foreach ($sets as $set) {
Assert::fileExists($set);
$this->import($set);
}
}
public function disableParallel(): void
{
$parameters = $this->parameters();
$parameters->set(Option::PARALLEL, false);
}
public function parallel(): void
{
$parameters = $this->parameters();
$parameters->set(Option::PARALLEL, true);
}
/**
* @param array<int|string, mixed> $criteria
*/
public function skip(array $criteria): void
{
$parameters = $this->parameters();
$parameters->set(Option::SKIP, $criteria);
}
public function importNames(): void
{
$parameters = $this->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
}
public function disableImportNames(): void
{
$parameters = $this->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, false);
}
/**
* Set PHPStan custom config to load extensions and custom configuration to Rector.
* By default, the "phpstan.neon" path is used.
*/
public function phpstanConfig(string $filePath): void
{
Assert::fileExists($filePath);
$parameters = $this->parameters();
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, $filePath);
}
/**
* @param class-string<ConfigurableRectorInterface&RectorInterface> $rectorClass
* @param mixed[] $configuration
*/
public function ruleWithConfiguration(string $rectorClass, array $configuration): void
{
Assert::isAOf($rectorClass, RectorInterface::class);
Assert::isAOf($rectorClass, ConfigurableRectorInterface::class);
$services = $this->services();
$services->set($rectorClass)
->configure($configuration);
}
/**
* @param class-string<RectorInterface> $rectorClass
*/
public function rule(string $rectorClass): void
{
Assert::isAOf($rectorClass, RectorInterface::class);
$services = $this->services();
$services->set($rectorClass);
}
/**
* @param PhpVersion::* $phpVersion
*/
public function phpVersion(int $phpVersion): void
{
$parameters = $this->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, $phpVersion);
}
/**
* @param string[] $autoloadPaths
*/
public function autoloadPaths(array $autoloadPaths): void
{
Assert::allString($autoloadPaths);
$parameters = $this->parameters();
$parameters->set(Option::AUTOLOAD_PATHS, $autoloadPaths);
}
/**
* @param string[] $bootstrapFiles
*/
public function bootstrapFiles(array $bootstrapFiles): void
{
Assert::allString($bootstrapFiles);
$parameters = $this->parameters();
$parameters->set(Option::BOOTSTRAP_FILES, $bootstrapFiles);
}
}