File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types = 1 );
4
+
5
+ namespace Lookyman \PHPStan \Symfony \Exception ;
6
+
7
+ final class XmlContainerNotExistsException extends \InvalidArgumentException
8
+ {
9
+
10
+ }
Original file line number Diff line number Diff line change 4
4
5
5
namespace Lookyman \PHPStan \Symfony ;
6
6
7
+ use Lookyman \PHPStan \Symfony \Exception \XmlContainerNotExistsException ;
7
8
use PhpParser \Node ;
8
9
use PhpParser \Node \Expr \ClassConstFetch ;
9
10
use PhpParser \Node \Name ;
@@ -21,7 +22,11 @@ public function __construct(string $containerXml)
21
22
{
22
23
$ this ->services = $ aliases = [];
23
24
/** @var \SimpleXMLElement $def */
24
- foreach (\simplexml_load_file ($ containerXml )->services ->service as $ def ) {
25
+ $ xml = @\simplexml_load_file ($ containerXml );
26
+ if ($ xml === false ) {
27
+ throw new XmlContainerNotExistsException (\sprintf ('Container %s not exists ' , $ containerXml ));
28
+ }
29
+ foreach ($ xml ->services ->service as $ def ) {
25
30
$ attrs = $ def ->attributes ();
26
31
if (!isset ($ attrs ->id )) {
27
32
continue ;
Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ public function testGetServiceFromNode(array $service)
24
24
self ::assertEquals ($ service , $ serviceMap ->getServiceFromNode (new String_ ($ service ['id ' ])));
25
25
}
26
26
27
+ /**
28
+ * @expectedException \Lookyman\PHPStan\Symfony\Exception\XmlContainerNotExistsException
29
+ */
30
+ public function testFileNotExists ()
31
+ {
32
+ new ServiceMap (__DIR__ . '/foo.xml ' );
33
+ }
34
+
27
35
public function getServiceFromNodeProvider (): array
28
36
{
29
37
return [
You can’t perform that action at this time.
0 commit comments