forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectConfigHelper.php
More file actions
66 lines (55 loc) · 1.41 KB
/
Copy pathProjectConfigHelper.php
File metadata and controls
66 lines (55 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php declare(strict_types = 1);
namespace PHPStan\DependencyInjection;
use Nette\DI\Definitions\Statement;
use function array_merge;
use function array_unique;
use function array_values;
use function is_array;
use function is_string;
final class ProjectConfigHelper
{
/**
* @param array<mixed> $projectConfig
* @return list<string>
*/
public static function getServiceClassNames(array $projectConfig): array
{
$services = array_merge(
$projectConfig['services'] ?? [],
$projectConfig['rules'] ?? [],
);
$classes = [];
foreach ($services as $service) {
$classes = array_merge($classes, self::getClassesFromConfigDefinition($service));
if (!is_array($service)) {
continue;
}
foreach (['class', 'factory', 'implement'] as $key) {
if (!isset($service[$key])) {
continue;
}
$classes = array_merge($classes, self::getClassesFromConfigDefinition($service[$key]));
}
}
return array_values(array_unique($classes));
}
/**
* @param mixed $definition
* @return string[]
*/
private static function getClassesFromConfigDefinition($definition): array
{
if (is_string($definition)) {
return [$definition];
}
if ($definition instanceof Statement) {
$entity = $definition->entity;
if (is_string($entity)) {
return [$entity];
} elseif (is_array($entity) && isset($entity[0]) && is_string($entity[0])) {
return [$entity[0]];
}
}
return [];
}
}