33namespace PHPStan \Symfony ;
44
55use SimpleXMLElement ;
6+ use function count ;
67use function file_get_contents ;
8+ use function ksort ;
79use function simplexml_load_string ;
810use function sprintf ;
911use function strpos ;
@@ -39,35 +41,38 @@ public function create(): ServiceMap
3941 $ services = [];
4042 /** @var Service[] $aliases */
4143 $ 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- );
6644
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+ }
7176 }
7277 }
7378 foreach ($ aliases as $ service ) {
@@ -85,6 +90,8 @@ public function create(): ServiceMap
8590 );
8691 }
8792
93+ ksort ($ services );
94+
8895 return new DefaultServiceMap ($ services );
8996 }
9097
0 commit comments