Skip to content
This repository has been archived by the owner on Jun 26, 2018. It is now read-only.

Commit

Permalink
Merge 9422724 into 8e8fa73
Browse files Browse the repository at this point in the history
  • Loading branch information
mzk committed Dec 29, 2017
2 parents 8e8fa73 + 9422724 commit bc25319
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Exception/XmlContainerNotExistsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types = 1);

namespace Lookyman\PHPStan\Symfony\Exception;

final class XmlContainerNotExistsException extends \InvalidArgumentException
{

}
7 changes: 6 additions & 1 deletion src/ServiceMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Lookyman\PHPStan\Symfony;

use Lookyman\PHPStan\Symfony\Exception\XmlContainerNotExistsException;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Name;
Expand All @@ -21,7 +22,11 @@ public function __construct(string $containerXml)
{
$this->services = $aliases = [];
/** @var \SimpleXMLElement $def */
foreach (\simplexml_load_file($containerXml)->services->service as $def) {
$xml = @\simplexml_load_file($containerXml);
if ($xml === false) {
throw new XmlContainerNotExistsException(\sprintf('Container %s not exists', $containerXml));
}
foreach ($xml->services->service as $def) {
$attrs = $def->attributes();
if (!isset($attrs->id)) {
continue;
Expand Down
8 changes: 8 additions & 0 deletions tests/ServiceMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public function testGetServiceFromNode(array $service)
self::assertEquals($service, $serviceMap->getServiceFromNode(new String_($service['id'])));
}

/**
* @expectedException \Lookyman\PHPStan\Symfony\Exception\XmlContainerNotExistsException
*/
public function testFileNotExists()
{
new ServiceMap(__DIR__ . '/foo.xml');
}

public function getServiceFromNodeProvider(): array
{
return [
Expand Down

0 comments on commit bc25319

Please sign in to comment.