Xml   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 8
c 0
b 0
f 0
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A read() 0 11 3
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Storage\File;
13
14
use CaptainHook\App\Storage\File;
15
use RuntimeException;
16
17
/**
18
 * Class Xml
19
 *
20
 * @package CaptainHook
21
 * @author  Sebastian Feldmann <[email protected]>
22
 * @link    https://github.com/captainhook-git/captainhook
23
 * @since   Class available since Release 1.2.0
24
 */
25
final class Xml extends File
26
{
27
    /**
28
     * Read the xml file and return a SimpleXML object.
29
     *
30
     * @return \SimpleXMLElement
31
     */
32 8
    public function read()
33
    {
34 8
        $old    = libxml_use_internal_errors(true);
35 8
        $xml    = simplexml_load_file($this->path);
36 8
        $errors = libxml_get_errors();
37 8
        libxml_use_internal_errors($old);
38
39 8
        if (count($errors) || $xml === false) {
40 1
            throw new RuntimeException('xml file \'' . $this->path . '\': ' . $errors[0]->message);
41
        }
42 7
        return $xml;
43
    }
44
}
45