Completed
Push — master ( b06bec...8d39d6 )
by Xeriab
03:49
created

Xml   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 42
rs 10
c 0
b 0
f 0
ccs 19
cts 20
cp 0.95

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 4
            realpath($path),
30 6
            'SimpleXMLElement',
31 6
            LIBXML_NOWARNING | LIBXML_NOERROR
32 4
        );
33
34 6
        if ($data === false) {
35 3
            $lastError = libxml_get_last_error();
36
37 3
            if ($lastError !== false) {
38 3
                throw new ParseException([
39 3
                    'message' => $lastError->message,
40 3
                    'type' => $lastError->level,
41 3
                    'code' => $lastError->code,
42 3
                    'file' => $lastError->file,
43 3
                    'line' => $lastError->line,
44 2
                ]);
45
            }
46
        }
47
48 3
        return json_decode(json_encode($data), true);
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 3
    public function getSupportedFileExtensions()
55
    {
56 3
        return ['xml'];
57
    }
58
}
59
60
// END OF ./src/FileParser/Xml.php FILE
61