Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
13 / 13 |
XMLReader | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
13 / 13 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
getEntityList | |
100.00% |
1 / 1 |
3 | |
100.00% |
5 / 5 |
|||
handleEntityElement | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
<?php | |
declare(strict_types = 1); | |
namespace Siesta\XML; | |
use Siesta\Util\File; | |
/** | |
* @author Gregor Müller | |
*/ | |
class XMLReader | |
{ | |
/** | |
* @var \DomDocument | |
*/ | |
protected $xmlDocument; | |
/** | |
* @var string | |
*/ | |
protected $fileName; | |
/** | |
* @var XMLEntity[] | |
*/ | |
protected $xmlEntityList; | |
/** | |
* @param File $file | |
*/ | |
public function __construct(File $file) | |
{ | |
$this->fileName = $file->getAbsoluteFileName(); | |
$this->xmlDocument = $file->loadAsXML(); | |
$this->enityList = []; | |
} | |
/** | |
* @return XMLEntity[] | |
*/ | |
public function getEntityList() : array | |
{ | |
$domNodeList = $this->xmlDocument->getElementsByTagName(XMLEntity::ELEMENT_ENTITY_NAME); | |
foreach ($domNodeList as $node) { | |
if ($node->nodeType === XML_ELEMENT_NODE) { | |
$this->handleEntityElement($node); | |
} | |
} | |
return $this->xmlEntityList; | |
} | |
/** | |
* @param \DOMElement $entityElement | |
*/ | |
protected function handleEntityElement(\DOMElement $entityElement) | |
{ | |
$entityReader = new XMLEntity(); | |
$entityReader->fromXML(new XMLAccess($entityElement)); | |
$this->xmlEntityList[] = $entityReader; | |
} | |
} |