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 44
55namespace Lookyman \PHPStan \Symfony ;
66
7+ use Lookyman \PHPStan \Symfony \Exception \XmlContainerNotExistsException ;
78use PhpParser \Node ;
89use PhpParser \Node \Expr \ClassConstFetch ;
910use PhpParser \Node \Name ;
@@ -21,7 +22,11 @@ public function __construct(string $containerXml)
2122 {
2223 $ this ->services = $ aliases = [];
2324 /** @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 ) {
2530 $ attrs = $ def ->attributes ();
2631 if (!isset ($ attrs ->id )) {
2732 continue ;
Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ public function testGetServiceFromNode(array $service)
2424 self ::assertEquals ($ service , $ serviceMap ->getServiceFromNode (new String_ ($ service ['id ' ])));
2525 }
2626
27+ /**
28+ * @expectedException \Lookyman\PHPStan\Symfony\Exception\XmlContainerNotExistsException
29+ */
30+ public function testFileNotExists ()
31+ {
32+ new ServiceMap (__DIR__ . '/foo.xml ' );
33+ }
34+
2735 public function getServiceFromNodeProvider (): array
2836 {
2937 return [
You can’t perform that action at this time.
0 commit comments