Completed
Push — master ( aa9657...bb9832 )
by Sebastian
05:21
created

Xml::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

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