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