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

Xml::getSupportedFileExtensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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