XmlChecker::isValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Fxmlrpc\Serialization;
4
5
use Fxmlrpc\Serialization\Exception\ParserException;
6
7
/**
8
 * Class XmlChecker to check is correct XML.
9
 *
10
 * @author Piotr Olaszewski <[email protected]>
11
 */
12
final class XmlChecker
13
{
14
    /**
15
     * @param string $xml
16
     *
17
     * @return bool
18
     *
19
     * @throws ParserException
20
     */
21 2
    public static function isValid($xml)
22
    {
23 2
        $useErrors = libxml_use_internal_errors(true);
24
25 2
        $isCorrect = simplexml_load_string($xml);
26
27 2
        libxml_use_internal_errors($useErrors);
28
29 2
        if (false === $isCorrect) {
30 1
            throw ParserException::notXml($xml);
31
        }
32
33 1
        return true;
34
    }
35
}
36