Completed
Push — master ( 2b8886...d0ff07 )
by Xeriab
04:16
created

Xml   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 93.75%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 19 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
25
     */
26 6
    public function parse($path)
27
    {
28 6
        $data = simplexml_load_file($path, 'SimpleXMLElement', LIBXML_NOWARNING | LIBXML_NOERROR);
29
30 6
        if ($data === false) {
31 3
            $lastError = libxml_get_last_error();
32 3
            if ($lastError !== false) {
33 3
                throw new ParseException([
34 3
                    'message' => $lastError->message,
35 3
                    'type'    => $lastError->level,
36 3
                    'code'    => $lastError->code,
37 3
                    'file'    => $lastError->file,
38 3
                    'line'    => $lastError->line,
39 2
                ]);
40
            }
41
        }
42
43 3
        return \json_decode(\json_encode($data), true);
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49 3
    public function getSupportedFileExtensions()
50
    {
51 3
        return ['xml'];
52
    }
53
}
54
55
#: END OF ./src/FileParser/Xml.php FILE
56