mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-26 20:53:31 +00:00
bin: use LevelConfigShortcutFinder
This commit is contained in:
parent
f98b288076
commit
88d36e1607
|
@ -1,12 +1,12 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use Rector\Configuration\RectorConfigFilePathHelper;
|
||||
use Rector\Console\Application;
|
||||
use Rector\DependencyInjection\ContainerFactory;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symplify\PackageBuilder\Configuration\ConfigFilePathHelper;
|
||||
use Symplify\PackageBuilder\Configuration\LevelConfigShortcutFinder;
|
||||
use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory;
|
||||
|
||||
// Performance boost
|
||||
|
@ -17,7 +17,7 @@ require_once __DIR__ . '/rector_bootstrap.php';
|
|||
|
||||
try {
|
||||
// 1. Detect configuration from --level
|
||||
$configFile = (new RectorConfigFilePathHelper())->resolveLevel(new ArgvInput());
|
||||
$configFile = (new LevelConfigShortcutFinder())->resolveLevel(new ArgvInput(), __DIR__ . '/../src/config/level');
|
||||
|
||||
// 2. Or from --config
|
||||
if ($configFile === null) {
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Configuration;
|
||||
|
||||
use SplFileInfo;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
final class RectorConfigFilePathHelper
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const LEVEL_OPTION_NAME = '--level';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $levelDirectory = __DIR__ . '/../config/level';
|
||||
|
||||
public function resolveLevel(InputInterface $input): ?string
|
||||
{
|
||||
if (! $input->hasParameterOption(self::LEVEL_OPTION_NAME)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$levelConfigName = $input->getParameterOption(self::LEVEL_OPTION_NAME);
|
||||
|
||||
$finder = Finder::create()
|
||||
->files()
|
||||
->name($levelConfigName . '.yml')
|
||||
->in($this->levelDirectory);
|
||||
|
||||
$firstFile = self::getFirstFileFromFinder($finder);
|
||||
if (! $firstFile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $firstFile->getRealPath();
|
||||
}
|
||||
|
||||
private function getFirstFileFromFinder(Finder $finder): ?SplFileInfo
|
||||
{
|
||||
$iterator = $finder->getIterator();
|
||||
$iterator->rewind();
|
||||
|
||||
return $iterator->current();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user