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

Xml::getSupportedFileExtensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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