2019-10-13 05:59:52 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2018-08-06 10:31:17 +00:00
|
|
|
namespace Rector\NodeTypeResolver\DependencyInjection;
|
|
|
|
|
|
|
|
use PHPStan\Analyser\NodeScopeResolver;
|
|
|
|
use PHPStan\Analyser\ScopeFactory;
|
|
|
|
use PHPStan\Analyser\TypeSpecifier;
|
2020-04-01 01:55:44 +00:00
|
|
|
use PHPStan\Dependency\DependencyResolver;
|
2019-12-08 21:00:38 +00:00
|
|
|
use PHPStan\DependencyInjection\Container;
|
2018-08-06 10:31:17 +00:00
|
|
|
use PHPStan\DependencyInjection\ContainerFactory;
|
2020-01-06 12:22:18 +00:00
|
|
|
use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider;
|
2020-04-01 01:55:44 +00:00
|
|
|
use PHPStan\File\FileHelper;
|
2020-01-14 14:25:42 +00:00
|
|
|
use PHPStan\PhpDoc\TypeNodeResolver;
|
2020-01-13 13:34:18 +00:00
|
|
|
use PHPStan\Reflection\ReflectionProvider;
|
2020-12-24 16:31:24 +00:00
|
|
|
use Rector\Core\Configuration\Option;
|
2021-02-28 07:47:48 +00:00
|
|
|
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
|
2021-08-22 15:42:22 +00:00
|
|
|
use RectorPrefix20210822\Symplify\PackageBuilder\Parameter\ParameterProvider;
|
2020-01-14 14:25:42 +00:00
|
|
|
/**
|
|
|
|
* Factory so Symfony app can use services from PHPStan container
|
|
|
|
* @see packages/NodeTypeResolver/config/config.yaml:17
|
|
|
|
*/
|
2018-08-06 10:31:17 +00:00
|
|
|
final class PHPStanServicesFactory
|
|
|
|
{
|
|
|
|
/**
|
2021-08-22 23:17:31 +00:00
|
|
|
* @var \RectorPrefix20210822\PHPStan\DependencyInjection\Container
|
2018-08-06 10:31:17 +00:00
|
|
|
*/
|
|
|
|
private $container;
|
2021-08-22 15:42:22 +00:00
|
|
|
public function __construct(\RectorPrefix20210822\Symplify\PackageBuilder\Parameter\ParameterProvider $parameterProvider)
|
2018-08-06 10:31:17 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
$containerFactory = new \PHPStan\DependencyInjection\ContainerFactory(\getcwd());
|
2019-07-28 13:46:37 +00:00
|
|
|
$additionalConfigFiles = [];
|
2021-05-10 22:23:08 +00:00
|
|
|
$additionalConfigFiles[] = $parameterProvider->provideStringParameter(\Rector\Core\Configuration\Option::PHPSTAN_FOR_RECTOR_PATH);
|
2021-03-12 01:21:29 +00:00
|
|
|
$additionalConfigFiles[] = __DIR__ . '/../../../config/phpstan/static-reflection.neon';
|
|
|
|
$additionalConfigFiles[] = __DIR__ . '/../../../config/phpstan/better-infer.neon';
|
2021-05-09 20:15:43 +00:00
|
|
|
$existingAdditionalConfigFiles = \array_filter($additionalConfigFiles, 'file_exists');
|
|
|
|
$this->container = $containerFactory->create(\sys_get_temp_dir(), $existingAdditionalConfigFiles, []);
|
2018-08-06 10:31:17 +00:00
|
|
|
}
|
2020-03-28 23:06:05 +00:00
|
|
|
/**
|
|
|
|
* @api
|
|
|
|
*/
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createReflectionProvider() : \PHPStan\Reflection\ReflectionProvider
|
2018-08-06 10:31:17 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
return $this->container->getByType(\PHPStan\Reflection\ReflectionProvider::class);
|
2018-08-06 10:31:17 +00:00
|
|
|
}
|
2020-03-28 23:06:05 +00:00
|
|
|
/**
|
|
|
|
* @api
|
|
|
|
*/
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createNodeScopeResolver() : \PHPStan\Analyser\NodeScopeResolver
|
2018-08-06 10:31:17 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
return $this->container->getByType(\PHPStan\Analyser\NodeScopeResolver::class);
|
2018-08-06 10:31:17 +00:00
|
|
|
}
|
2020-03-28 23:06:05 +00:00
|
|
|
/**
|
|
|
|
* @api
|
|
|
|
*/
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createTypeSpecifier() : \PHPStan\Analyser\TypeSpecifier
|
2018-08-06 10:31:17 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
return $this->container->getByType(\PHPStan\Analyser\TypeSpecifier::class);
|
2018-08-06 10:31:17 +00:00
|
|
|
}
|
2020-03-28 23:06:05 +00:00
|
|
|
/**
|
|
|
|
* @api
|
|
|
|
*/
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createScopeFactory() : \PHPStan\Analyser\ScopeFactory
|
2018-08-06 10:31:17 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
return $this->container->getByType(\PHPStan\Analyser\ScopeFactory::class);
|
2018-08-06 10:31:17 +00:00
|
|
|
}
|
2020-04-01 01:55:44 +00:00
|
|
|
/**
|
|
|
|
* @api
|
|
|
|
*/
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createDependencyResolver() : \PHPStan\Dependency\DependencyResolver
|
2020-04-01 01:55:44 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
return $this->container->getByType(\PHPStan\Dependency\DependencyResolver::class);
|
2020-04-01 01:55:44 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @api
|
|
|
|
*/
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createFileHelper() : \PHPStan\File\FileHelper
|
2020-04-01 01:55:44 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
return $this->container->getByType(\PHPStan\File\FileHelper::class);
|
2020-04-01 01:55:44 +00:00
|
|
|
}
|
2020-03-28 23:06:05 +00:00
|
|
|
/**
|
|
|
|
* @api
|
|
|
|
*/
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createOperatorTypeSpecifyingExtensionRegistryProvider() : \PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider
|
2020-01-06 12:22:18 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
return $this->container->getByType(\PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider::class);
|
2020-01-06 08:43:51 +00:00
|
|
|
}
|
2020-03-28 23:06:05 +00:00
|
|
|
/**
|
|
|
|
* @api
|
|
|
|
*/
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createTypeNodeResolver() : \PHPStan\PhpDoc\TypeNodeResolver
|
2020-01-14 14:25:42 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
return $this->container->getByType(\PHPStan\PhpDoc\TypeNodeResolver::class);
|
2020-01-14 14:25:42 +00:00
|
|
|
}
|
2021-02-28 07:47:48 +00:00
|
|
|
/**
|
|
|
|
* @api
|
|
|
|
*/
|
2021-05-10 22:23:08 +00:00
|
|
|
public function createDynamicSourceLocatorProvider() : \Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider
|
2021-02-28 07:47:48 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
return $this->container->getByType(\Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider::class);
|
2021-02-28 07:47:48 +00:00
|
|
|
}
|
2018-08-06 10:31:17 +00:00
|
|
|
}
|