Completed
Push — master ( 2f0aca...1e79f6 )
by Sebastian
03:02
created

Xml::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
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
    public function read()
30
    {
31
        $old    = libxml_use_internal_errors(true);
32
        $xml    = simplexml_load_file($this->path);
33
        $errors = libxml_get_errors();
34
        libxml_use_internal_errors($old);
35
36
        if (count($errors)) {
37
            throw new \RuntimeException('xml file \''. $this->path . '\': ' . $errors[0]->message);
38
        }
39
        return $xml;
40
    }
41
}
42