mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-21 01:41:00 +01:00
add check class existance scripts (#1978)
add check class existance scripts
This commit is contained in:
commit
c44d86afb7
@ -47,6 +47,7 @@ script:
|
||||
if [[ $RUN_RECTOR == true ]]; then
|
||||
bin/rector process src --set symfony40 --dry-run
|
||||
composer docs
|
||||
php bin/check_class_existance_in_yaml_configs.php
|
||||
fi
|
||||
|
||||
# Eat your own dog food
|
||||
|
46
bin/check_class_existance_in_yaml_configs.php
Normal file
46
bin/check_class_existance_in_yaml_configs.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$finder = (new Finder())->name('*.yaml')
|
||||
->in(__DIR__ . '/../config')
|
||||
->files();
|
||||
|
||||
/** @var SplFileInfo $splFileInfo */
|
||||
foreach ($finder as $splFileInfo) {
|
||||
$yamlContent = Yaml::parseFile($splFileInfo->getRealPath());
|
||||
if (! isset($yamlContent['services'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (array_keys($yamlContent['services']) as $service) {
|
||||
// configuration → skip
|
||||
if (Strings::startsWith($service, '_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// autodiscovery → skip
|
||||
if (Strings::endsWith($service, '\\')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ClassExistenceStaticHelper::doesClassLikeExist($service)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new ShouldNotHappenException(sprintf(
|
||||
'Service "%s" from config "%s" was not found. Check if it really exists or is even autoload, please',
|
||||
$service,
|
||||
$splFileInfo->getRealPath()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
echo 'All configs have existing services - good job!' . PHP_EOL;
|
@ -21,7 +21,7 @@ services:
|
||||
'GuzzleHttp\Pool':
|
||||
batch: 'GuzzleHttp\Pool\batch'
|
||||
|
||||
Rector\Guzzle\Rector\FuncCall\MessageAsArrayRector: ~
|
||||
Rector\Guzzle\Rector\MethodCall\MessageAsArrayRector: ~
|
||||
Rector\Rector\MethodCall\RenameMethodRector:
|
||||
GuzzleHttp\Message\MessageInterface:
|
||||
getHeaderLines: 'getHeaderAsArray'
|
||||
|
@ -1,22 +0,0 @@
|
||||
services:
|
||||
Rector\PhpParser\Rector\IdentifierRector: ~
|
||||
Rector\PhpParser\Rector\ParamAndStaticVarNameRector: ~
|
||||
Rector\PhpParser\Rector\CatchAndClosureUseNameRector: ~
|
||||
Rector\PhpParser\Rector\SetLineRector: ~
|
||||
Rector\PhpParser\Rector\RemoveNodeRector: ~
|
||||
Rector\PhpParser\Rector\UseWithAliasRector: ~
|
||||
|
||||
Rector\Rector\Property\RenamePropertyRector:
|
||||
'PhpParser\Node\Stmt\Class_':
|
||||
'type': 'flags'
|
||||
'PhpParser\Node\Stmt\ClassMethod':
|
||||
'type': 'flags'
|
||||
'PhpParser\Node\Stmt\Property':
|
||||
'type': 'flags'
|
||||
|
||||
Rector\Rector\Constant\RenameClassConstantRector:
|
||||
'PhpParser\Node\Stmt\Class_':
|
||||
'VISIBILITY_MODIFER_MASK': 'VISIBILITY_MODIFIER_MASK'
|
||||
|
||||
Rector\Rector\Class_\RenameClassRector:
|
||||
'PhpParser\BuilderAbstract': 'PhpParser\Builder'
|
@ -167,7 +167,8 @@ CODE_SAMPLE
|
||||
// resolve value types
|
||||
$firstArgumentValue = $node->args[0]->value;
|
||||
if (! $firstArgumentValue instanceof Array_) {
|
||||
throw new ShouldNotHappenException();
|
||||
// nothing we can do
|
||||
return null;
|
||||
}
|
||||
|
||||
// rename method to new one handling non-array input
|
||||
|
Loading…
x
Reference in New Issue
Block a user