add check class existance scripts (#1978)

add check class existance scripts
This commit is contained in:
Tomáš Votruba 2019-09-13 08:39:28 +02:00 committed by GitHub
commit c44d86afb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 24 deletions

View File

@ -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

View 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;

View File

@ -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'

View File

@ -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'

View File

@ -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