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

Xml   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 20
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A read() 0 12 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