|
2 | 2 |
|
3 | 3 | namespace PHPStan\Analyser\ResultCache; |
4 | 4 |
|
5 | | -use Nette\DI\Definitions\Statement; |
6 | 5 | use Nette\Neon\Neon; |
7 | 6 | use PHPStan\Analyser\AnalyserResult; |
8 | 7 | use PHPStan\Analyser\Error; |
9 | 8 | use PHPStan\Collectors\CollectedData; |
10 | 9 | use PHPStan\Command\Output; |
11 | 10 | use PHPStan\Dependency\ExportedNodeFetcher; |
12 | 11 | use PHPStan\Dependency\RootExportedNode; |
| 12 | +use PHPStan\DependencyInjection\ProjectConfigHelper; |
13 | 13 | use PHPStan\File\CouldNotReadFileException; |
14 | 14 | use PHPStan\File\FileFinder; |
15 | 15 | use PHPStan\File\FileWriter; |
|
23 | 23 | use function array_filter; |
24 | 24 | use function array_key_exists; |
25 | 25 | use function array_keys; |
26 | | -use function array_merge; |
27 | 26 | use function array_unique; |
28 | 27 | use function array_values; |
29 | 28 | use function count; |
30 | 29 | use function get_loaded_extensions; |
31 | 30 | use function implode; |
32 | 31 | use function is_array; |
33 | 32 | use function is_file; |
34 | | -use function is_string; |
35 | 33 | use function ksort; |
36 | 34 | use function sha1_file; |
37 | 35 | use function sort; |
@@ -636,70 +634,32 @@ private function getProjectExtensionFiles(?array $projectConfig, array $dependen |
636 | 634 | $this->alreadyProcessed = []; |
637 | 635 | $projectExtensionFiles = []; |
638 | 636 | if ($projectConfig !== null) { |
639 | | - $services = array_merge( |
640 | | - $projectConfig['services'] ?? [], |
641 | | - $projectConfig['rules'] ?? [], |
642 | | - ); |
643 | | - foreach ($services as $service) { |
644 | | - $classes = $this->getClassesFromConfigDefinition($service); |
645 | | - if (is_array($service)) { |
646 | | - foreach (['class', 'factory', 'implement'] as $key) { |
647 | | - if (!isset($service[$key])) { |
648 | | - continue; |
649 | | - } |
650 | | - |
651 | | - $classes = array_merge($classes, $this->getClassesFromConfigDefinition($service[$key])); |
652 | | - } |
| 637 | + $classes = ProjectConfigHelper::getServiceClassNames($projectConfig); |
| 638 | + foreach ($classes as $class) { |
| 639 | + if (!$this->reflectionProvider->hasClass($class)) { |
| 640 | + continue; |
653 | 641 | } |
654 | 642 |
|
655 | | - foreach (array_unique($classes) as $class) { |
656 | | - if (!$this->reflectionProvider->hasClass($class)) { |
657 | | - continue; |
658 | | - } |
| 643 | + $classReflection = $this->reflectionProvider->getClass($class); |
| 644 | + $fileName = $classReflection->getFileName(); |
| 645 | + if ($fileName === null) { |
| 646 | + continue; |
| 647 | + } |
659 | 648 |
|
660 | | - $classReflection = $this->reflectionProvider->getClass($class); |
661 | | - $fileName = $classReflection->getFileName(); |
662 | | - if ($fileName === null) { |
| 649 | + $allServiceFiles = $this->getAllDependencies($fileName, $dependencies); |
| 650 | + foreach ($allServiceFiles as $serviceFile) { |
| 651 | + if (array_key_exists($serviceFile, $projectExtensionFiles)) { |
663 | 652 | continue; |
664 | 653 | } |
665 | 654 |
|
666 | | - $allServiceFiles = $this->getAllDependencies($fileName, $dependencies); |
667 | | - foreach ($allServiceFiles as $serviceFile) { |
668 | | - if (array_key_exists($serviceFile, $projectExtensionFiles)) { |
669 | | - continue; |
670 | | - } |
671 | | - |
672 | | - $projectExtensionFiles[$serviceFile] = $this->getFileHash($serviceFile); |
673 | | - } |
| 655 | + $projectExtensionFiles[$serviceFile] = $this->getFileHash($serviceFile); |
674 | 656 | } |
675 | 657 | } |
676 | 658 | } |
677 | 659 |
|
678 | 660 | return $projectExtensionFiles; |
679 | 661 | } |
680 | 662 |
|
681 | | - /** |
682 | | - * @param mixed $definition |
683 | | - * @return string[] |
684 | | - */ |
685 | | - private function getClassesFromConfigDefinition($definition): array |
686 | | - { |
687 | | - if (is_string($definition)) { |
688 | | - return [$definition]; |
689 | | - } |
690 | | - |
691 | | - if ($definition instanceof Statement) { |
692 | | - $entity = $definition->entity; |
693 | | - if (is_string($entity)) { |
694 | | - return [$entity]; |
695 | | - } elseif (is_array($entity) && isset($entity[0]) && is_string($entity[0])) { |
696 | | - return [$entity[0]]; |
697 | | - } |
698 | | - } |
699 | | - |
700 | | - return []; |
701 | | - } |
702 | | - |
703 | 663 | /** |
704 | 664 | * @param array<string, array<int, string>> $dependencies |
705 | 665 | * @return array<int, string> |
|
0 commit comments