Completed
Pull Request — master (#90)
by
unknown
03:21 queued 03:21
created

XmlCheckRule::doValidation()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 3
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace whm\Smoke\Rules\Xml;
4
5
use whm\Smoke\Http\Response;
6
use whm\Smoke\Rules\StandardRule;
7
8
/**
9
 * This rule checks if the found XML is valide.
10
 */
11
class XmlCheckRule extends StandardRule
12
{
13
    public function doValidation(Response $response)
14
    {
15
        $domDocument = new \DOMDocument();
16
        $success = @$domDocument->loadXML((string) $response->getBody());  // true/false
17
18
        $lastError = libxml_get_last_error();
19
        if (!$success || $lastError) {
20
            throw new \RuntimeException('The xml file '. $response->getUri() . ' is not well formed (last error: ' .
21
                    str_replace("\n", '', $lastError->message) . ').');
22
        }
23
    }
24
}
25