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

XmlCheckRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 14
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A doValidation() 0 11 3
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