fix stub loading location (#2130)

fix stub loading location
This commit is contained in:
Tomáš Votruba 2019-10-10 15:01:40 +01:00 committed by GitHub
commit ae06977ecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -7,6 +7,7 @@ use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Psr\Container\ContainerInterface;
@ -31,10 +32,19 @@ final class StaticContainerGetDynamicMethodReturnTypeExtension implements Dynami
): Type {
$valueType = $scope->getType($methodCall->args[0]->value);
// we don't know what it is
if ($valueType instanceof MixedType) {
return $valueType;
}
if ($valueType instanceof ConstantStringType) {
return new ObjectType($valueType->getValue());
}
throw new ShouldNotHappenException();
throw new ShouldNotHappenException(sprintf(
'%s type given, only "%s" is supported',
get_class($valueType),
ConstantStringType::class
));
}
}

View File

@ -14,6 +14,7 @@ use Rector\Extension\ReportingExtensionRunner;
use Rector\FileSystem\FilesFinder;
use Rector\Guard\RectorGuard;
use Rector\PhpParser\NodeTraverser\RectorNodeTraverser;
use Rector\Stubs\StubLoader;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@ -72,6 +73,11 @@ final class ProcessCommand extends AbstractCommand
*/
private $rectorNodeTraverser;
/**
* @var StubLoader
*/
private $stubLoader;
/**
* @param string[] $fileExtensions
*/
@ -85,6 +91,7 @@ final class ProcessCommand extends AbstractCommand
OutputFormatterCollector $outputFormatterCollector,
ReportingExtensionRunner $reportingExtensionRunner,
RectorNodeTraverser $rectorNodeTraverser,
StubLoader $stubLoader,
array $fileExtensions
) {
$this->filesFinder = $phpFilesFinder;
@ -97,6 +104,7 @@ final class ProcessCommand extends AbstractCommand
$this->outputFormatterCollector = $outputFormatterCollector;
$this->reportingExtensionRunner = $reportingExtensionRunner;
$this->rectorNodeTraverser = $rectorNodeTraverser;
$this->stubLoader = $stubLoader;
parent::__construct();
}
@ -148,6 +156,7 @@ final class ProcessCommand extends AbstractCommand
$this->configuration->setAreAnyPhpRectorsLoaded((bool) $this->rectorNodeTraverser->getPhpRectorCount());
$this->rectorGuard->ensureSomeRectorsAreRegistered();
$this->stubLoader->loadStubs();
$source = (array) $input->getArgument(Option::SOURCE);