Completed
Push — master ( 0849f8...e0934d )
by Xeriab
06:28
created

Xml   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 42
ccs 15
cts 16
cp 0.9375
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B parse() 0 24 3
A getSupportedFileExtensions() 0 4 1
1
<?php
2
3
/**
4
 * Konfig
5
 *
6
 * Yet another simple configuration loader library.
7
 *
8
 * @author  Xeriab Nabil (aka KodeBurner) <[email protected]>
9
 * @license https://raw.github.com/xeriab/konfig/master/LICENSE MIT
10
 * @link    https://xeriab.github.io/projects/konfig
11
 */
12
13
namespace Exen\Konfig\FileParser;
14
15
use Exen\Konfig\Exception\ParseException;
16
17
class Xml extends AbstractFileParser
18
{
19
    /**
20
     * {@inheritDoc}
21
     * Loads a XML file as an array
22
     *
23
     * @throws ParseException If there is an error parsing XML file
24
     * @since 0.1.0
25
     */
26 6
    public function parse($path)
27
    {
28 6
        $data = simplexml_load_file(
29
            realpath($path),
30 6
            'SimpleXMLElement',
31 3
            LIBXML_NOWARNING | LIBXML_NOERROR
32 3
        );
33 3
34 3
        if ($data === false) {
35 3
            $lastError = libxml_get_last_error();
36 3
37 3
            if ($lastError !== false) {
38 3
                throw new ParseException([
39 2
                    'message' => $lastError->message,
40
                    'type' => $lastError->level,
41
                    'code' => $lastError->code,
42
                    'file' => $lastError->file,
43 3
                    'line' => $lastError->line,
44
                ]);
45
            }
46
        }
47
48
        return json_decode(json_encode($data), true);
49 3
    }
50
51 3
    /**
52
     * {@inheritDoc}
53
     */
54
    public function getSupportedFileExtensions()
55
    {
56
        return ['xml'];
57
    }
58
}
59
60
// END OF ./src/FileParser/Xml.php FILE
61