mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-27 21:23:31 +00:00
make RectorServiceParametersShifter report better error in case of invalid configuration
This commit is contained in:
parent
e2a8659b2c
commit
fcb865767a
|
@ -4,6 +4,7 @@ use Nette\Utils\Strings;
|
||||||
use Rector\Set\SetProvider;
|
use Rector\Set\SetProvider;
|
||||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
use Symplify\PackageBuilder\Console\ShellCode;
|
||||||
|
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
@ -11,10 +12,20 @@ $setProvider = new SetProvider();
|
||||||
|
|
||||||
// any file to be tested
|
// any file to be tested
|
||||||
$file = 'src/Rector/AbstractRector.php';
|
$file = 'src/Rector/AbstractRector.php';
|
||||||
|
$excludedSets = [
|
||||||
|
// required Kernel class to be set in parameters
|
||||||
|
'symfony-code-quality'
|
||||||
|
];
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
foreach ($setProvider->provide() as $setName) {
|
foreach ($setProvider->provide() as $setName) {
|
||||||
|
if (in_array($setName, $excludedSets, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$command = ['php', 'bin/rector', 'process', $file, '--set', $setName, '--dry-run'];
|
$command = ['php', 'bin/rector', 'process', $file, '--set', $setName, '--dry-run'];
|
||||||
|
|
||||||
|
|
||||||
$process = new Process($command, __DIR__ . '/..');
|
$process = new Process($command, __DIR__ . '/..');
|
||||||
echo sprintf('Set "%s" is OK' . PHP_EOL, $setName);
|
echo sprintf('Set "%s" is OK' . PHP_EOL, $setName);
|
||||||
|
|
||||||
|
@ -25,7 +36,17 @@ foreach ($setProvider->provide() as $setName) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $processFailedException->getMessage();
|
$errors[] = $processFailedException->getMessage();
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($errors === []) {
|
||||||
|
exit(ShellCode::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
echo $error;
|
||||||
|
echo PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(ShellCode::ERROR);
|
||||||
|
|
|
@ -32,8 +32,7 @@ services:
|
||||||
Rector\Celebrity\Rector\FuncCall\SetTypeToCastRector: ~
|
Rector\Celebrity\Rector\FuncCall\SetTypeToCastRector: ~
|
||||||
|
|
||||||
# class { var $value; } → class { public $value; }
|
# class { var $value; } → class { public $value; }
|
||||||
Rector\Php52\Rector\Property\VarToPublicPropertyRector: ~pu
|
Rector\Php52\Rector\Property\VarToPublicPropertyRector: ~
|
||||||
|
|
||||||
|
|
||||||
# false or true → false || true
|
# false or true → false || true
|
||||||
# false and true → false && true
|
# false and true → false && true
|
||||||
|
|
|
@ -38,8 +38,9 @@ services:
|
||||||
addConfig: load
|
addConfig: load
|
||||||
|
|
||||||
Rector\Rector\Interface_\RemoveInterfacesRector:
|
Rector\Rector\Interface_\RemoveInterfacesRector:
|
||||||
# Removes "implements IPresenter"
|
$interfacesToRemove:
|
||||||
- Nette\Application\IPresenter
|
# Removes "implements IPresenter"
|
||||||
|
- Nette\Application\IPresenter
|
||||||
|
|
||||||
Rector\Renaming\Rector\Constant\RenameClassConstantRector:
|
Rector\Renaming\Rector\Constant\RenameClassConstantRector:
|
||||||
Nette\Http\*Response:
|
Nette\Http\*Response:
|
||||||
|
|
|
@ -18,8 +18,11 @@ final class RenameTesterTestToPHPUnitToTestFileRector extends AbstractFileSystem
|
||||||
public function refactor(SmartFileInfo $smartFileInfo): void
|
public function refactor(SmartFileInfo $smartFileInfo): void
|
||||||
{
|
{
|
||||||
$oldRealPath = $smartFileInfo->getRealPath();
|
$oldRealPath = $smartFileInfo->getRealPath();
|
||||||
$newRealPath = $this->createNewRealPath($oldRealPath);
|
if (! Strings::endsWith($oldRealPath, '*.phpt')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newRealPath = $this->createNewRealPath($oldRealPath);
|
||||||
if ($newRealPath === $oldRealPath) {
|
if ($newRealPath === $oldRealPath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Rector\DependencyInjection\Loader;
|
||||||
|
|
||||||
use Nette\Utils\Strings;
|
use Nette\Utils\Strings;
|
||||||
use Rector\Exception\Configuration\InvalidConfigurationException;
|
use Rector\Exception\Configuration\InvalidConfigurationException;
|
||||||
|
use Rector\Exception\ShouldNotHappenException;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
@ -43,13 +44,13 @@ final class RectorServiceParametersShifter
|
||||||
* @param mixed[] $configuration
|
* @param mixed[] $configuration
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
public function process(array $configuration): array
|
public function process(array $configuration, string $file): array
|
||||||
{
|
{
|
||||||
if (! isset($configuration[self::SERVICES_KEY]) || ! is_array($configuration[self::SERVICES_KEY])) {
|
if (! isset($configuration[self::SERVICES_KEY]) || ! is_array($configuration[self::SERVICES_KEY])) {
|
||||||
return $configuration;
|
return $configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration[self::SERVICES_KEY] = $this->processServices($configuration[self::SERVICES_KEY]);
|
$configuration[self::SERVICES_KEY] = $this->processServices($configuration[self::SERVICES_KEY], $file);
|
||||||
|
|
||||||
return $configuration;
|
return $configuration;
|
||||||
}
|
}
|
||||||
|
@ -58,13 +59,21 @@ final class RectorServiceParametersShifter
|
||||||
* @param mixed[] $services
|
* @param mixed[] $services
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
private function processServices(array $services): array
|
private function processServices(array $services, string $file): array
|
||||||
{
|
{
|
||||||
foreach ($services as $serviceName => $serviceDefinition) {
|
foreach ($services as $serviceName => $serviceDefinition) {
|
||||||
if (! $this->isRectorClass($serviceName) || empty($serviceDefinition)) {
|
if (! $this->isRectorClass($serviceName) || empty($serviceDefinition)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! is_array($serviceDefinition)) {
|
||||||
|
throw new ShouldNotHappenException(sprintf(
|
||||||
|
'Rector rule "%s" has invalid configuration in "%s". Fix it to an array',
|
||||||
|
$serviceName,
|
||||||
|
$file
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
$nonReservedNonVariables = $this->resolveRectorConfiguration($serviceDefinition);
|
$nonReservedNonVariables = $this->resolveRectorConfiguration($serviceDefinition);
|
||||||
|
|
||||||
// nothing to change
|
// nothing to change
|
||||||
|
|
|
@ -47,7 +47,7 @@ final class TolerantRectorYamlFileLoader extends AbstractParameterMergingYamlFil
|
||||||
|
|
||||||
$this->classExistenceValidator->ensureClassesAreValid($configuration, $file);
|
$this->classExistenceValidator->ensureClassesAreValid($configuration, $file);
|
||||||
|
|
||||||
$configuration = $this->rectorServiceParametersShifter->process($configuration);
|
$configuration = $this->rectorServiceParametersShifter->process($configuration, $file);
|
||||||
|
|
||||||
return $this->parameterInImportResolver->process($configuration);
|
return $this->parameterInImportResolver->process($configuration);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user