add check class existance scripts

This commit is contained in:
Tomas Votruba 2019-09-12 20:24:37 +02:00
parent 3c4f5e2b35
commit 60232eca21
4 changed files with 48 additions and 23 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'