-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReader.php
More file actions
43 lines (37 loc) · 1.05 KB
/
Reader.php
File metadata and controls
43 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace G4\CodeCoverage;
use G4\CodeCoverage\Exceptions\InvalidXmlFileFormatException;
use G4\ValueObject\RealPath;
class Reader
{
/**
* @var RealPath
*/
private $reportPath;
/**
* Reader constructor.
* @param RealPath $reportPath
*/
public function __construct(RealPath $reportPath)
{
$this->reportPath = $reportPath;
}
/**
* @return \SimpleXMLElement
* @throws InvalidXmlFileFormatException
*/
public function read()
{
$xml = simplexml_load_file((string) $this->reportPath);
if (!$xml instanceof \SimpleXMLElement
|| $xml->getName() !== ParamsConsts::COVERAGE
|| !$xml->project instanceof \SimpleXMLElement
|| $xml->project->getName() !== ParamsConsts::PROJECT
|| !$xml->project->metrics instanceof \SimpleXMLElement
|| $xml->project->metrics->getName() !== ParamsConsts::METRICS
) {
throw new InvalidXmlFileFormatException($this->reportPath);
}
return $xml;
}
}