Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
63.64% |
7 / 11 |
| XpathProvider | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
4.77 | |
63.64% |
7 / 11 |
| fetchData | |
0.00% |
0 / 1 |
4.77 | |
63.64% |
7 / 11 |
|||
| <?php | |
| namespace Alxvng\QATracker\DataProvider; | |
| use SimpleXMLElement; | |
| class XpathProvider extends AbstractXpathProvider | |
| { | |
| public function fetchData(): float | |
| { | |
| $xml = new SimpleXMLElement(file_get_contents($this->inputFilePath)); | |
| if (!empty($this->namespaceParameters) && | |
| isset($this->namespaceParameters[static::NS_PREFIX], $this->namespaceParameters[static::NS_VALUE]) | |
| ) { | |
| $xml->registerXPathNamespace( | |
| $this->namespaceParameters[static::NS_PREFIX], | |
| $this->namespaceParameters[static::NS_VALUE] | |
| ); | |
| } | |
| $result = $xml->xpath($this->xpathQuery); | |
| $result = reset($result); | |
| if (!is_numeric((string) $result)) { | |
| throw new \RuntimeException(sprintf('The result of must be a numeric value, got "%s"', $result)); | |
| } | |
| return (float) $result; | |
| } | |
| } |