|
10 | 10 | use PhpParser\Node\Stmt\Return_;
|
11 | 11 | use PHPStan\Analyser\Scope;
|
12 | 12 | use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
|
| 13 | +use PHPStan\DependencyInjection\Container; |
| 14 | +use PHPStan\DependencyInjection\ParameterNotFoundException; |
13 | 15 | use PHPStan\Node\InClassNode;
|
14 | 16 | use PHPStan\Reflection\ClassReflection;
|
15 | 17 | use PHPStan\Reflection\ExtendedMethodReflection;
|
16 | 18 | use PHPStan\Reflection\MethodReflection;
|
17 |
| -use PHPStan\Symfony\Configuration as PHPStanSymfonyConfiguration; |
18 | 19 | use RecursiveDirectoryIterator;
|
19 | 20 | use RecursiveIteratorIterator;
|
20 | 21 | use ReflectionAttribute;
|
@@ -63,16 +64,17 @@ class SymfonyUsageProvider implements MemberUsageProvider
|
63 | 64 | private array $dicConstants = [];
|
64 | 65 |
|
65 | 66 | public function __construct(
|
66 |
| - ?PHPStanSymfonyConfiguration $symfonyConfiguration, |
| 67 | + Container $container, |
67 | 68 | ?bool $enabled,
|
68 | 69 | ?string $configDir
|
69 | 70 | )
|
70 | 71 | {
|
71 | 72 | $this->enabled = $enabled ?? $this->isSymfonyInstalled();
|
72 | 73 | $resolvedConfigDir = $configDir ?? $this->autodetectConfigDir();
|
| 74 | + $containerXmlPath = $this->getContainerXmlPath($container); |
73 | 75 |
|
74 |
| - if ($this->enabled && $symfonyConfiguration !== null && $symfonyConfiguration->getContainerXmlPath() !== null) { // @phpstan-ignore phpstanApi.method |
75 |
| - $this->fillDicClasses($symfonyConfiguration->getContainerXmlPath()); // @phpstan-ignore phpstanApi.method |
| 76 | + if ($this->enabled && $containerXmlPath !== null) { |
| 77 | + $this->fillDicClasses($containerXmlPath); |
76 | 78 | }
|
77 | 79 |
|
78 | 80 | if ($this->enabled && $resolvedConfigDir !== null) {
|
@@ -500,4 +502,16 @@ private function getConstantUsages(ClassReflection $classReflection): array
|
500 | 502 | return $usages;
|
501 | 503 | }
|
502 | 504 |
|
| 505 | + private function getContainerXmlPath(Container $container): ?string |
| 506 | + { |
| 507 | + try { |
| 508 | + /** @var array{containerXmlPath: string|null} $symfonyConfig */ |
| 509 | + $symfonyConfig = $container->getParameter('symfony'); |
| 510 | + |
| 511 | + return $symfonyConfig['containerXmlPath']; |
| 512 | + } catch (ParameterNotFoundException $e) { |
| 513 | + return null; |
| 514 | + } |
| 515 | + } |
| 516 | + |
503 | 517 | }
|
0 commit comments