|
3 | 3 | namespace PHPStan\Symfony;
|
4 | 4 |
|
5 | 5 | use SimpleXMLElement;
|
| 6 | +use function count; |
6 | 7 | use function file_get_contents;
|
7 | 8 | use function ksort;
|
8 | 9 | use function simplexml_load_string;
|
@@ -40,35 +41,38 @@ public function create(): ServiceMap
|
40 | 41 | $services = [];
|
41 | 42 | /** @var Service[] $aliases */
|
42 | 43 | $aliases = [];
|
43 |
| - foreach ($xml->services->service as $def) { |
44 |
| - /** @var SimpleXMLElement $attrs */ |
45 |
| - $attrs = $def->attributes(); |
46 |
| - if (!isset($attrs->id)) { |
47 |
| - continue; |
48 |
| - } |
49 |
| - |
50 |
| - $serviceTags = []; |
51 |
| - foreach ($def->tag as $tag) { |
52 |
| - $tagAttrs = ((array) $tag->attributes())['@attributes'] ?? []; |
53 |
| - $tagName = $tagAttrs['name']; |
54 |
| - unset($tagAttrs['name']); |
55 |
| - |
56 |
| - $serviceTags[] = new ServiceTag($tagName, $tagAttrs); |
57 |
| - } |
58 |
| - |
59 |
| - $service = new Service( |
60 |
| - $this->cleanServiceId((string) $attrs->id), |
61 |
| - isset($attrs->class) ? (string) $attrs->class : null, |
62 |
| - isset($attrs->public) && (string) $attrs->public === 'true', |
63 |
| - isset($attrs->synthetic) && (string) $attrs->synthetic === 'true', |
64 |
| - isset($attrs->alias) ? $this->cleanServiceId((string) $attrs->alias) : null, |
65 |
| - $serviceTags, |
66 |
| - ); |
67 | 44 |
|
68 |
| - if ($service->getAlias() !== null) { |
69 |
| - $aliases[] = $service; |
70 |
| - } else { |
71 |
| - $services[$service->getId()] = $service; |
| 45 | + if (count($xml->services) > 0) { |
| 46 | + foreach ($xml->services->service as $def) { |
| 47 | + /** @var SimpleXMLElement $attrs */ |
| 48 | + $attrs = $def->attributes(); |
| 49 | + if (!isset($attrs->id)) { |
| 50 | + continue; |
| 51 | + } |
| 52 | + |
| 53 | + $serviceTags = []; |
| 54 | + foreach ($def->tag as $tag) { |
| 55 | + $tagAttrs = ((array) $tag->attributes())['@attributes'] ?? []; |
| 56 | + $tagName = $tagAttrs['name']; |
| 57 | + unset($tagAttrs['name']); |
| 58 | + |
| 59 | + $serviceTags[] = new ServiceTag($tagName, $tagAttrs); |
| 60 | + } |
| 61 | + |
| 62 | + $service = new Service( |
| 63 | + $this->cleanServiceId((string) $attrs->id), |
| 64 | + isset($attrs->class) ? (string) $attrs->class : null, |
| 65 | + isset($attrs->public) && (string) $attrs->public === 'true', |
| 66 | + isset($attrs->synthetic) && (string) $attrs->synthetic === 'true', |
| 67 | + isset($attrs->alias) ? $this->cleanServiceId((string) $attrs->alias) : null, |
| 68 | + $serviceTags, |
| 69 | + ); |
| 70 | + |
| 71 | + if ($service->getAlias() !== null) { |
| 72 | + $aliases[] = $service; |
| 73 | + } else { |
| 74 | + $services[$service->getId()] = $service; |
| 75 | + } |
72 | 76 | }
|
73 | 77 | }
|
74 | 78 | foreach ($aliases as $service) {
|
|
0 commit comments