Completed
Push — master ( 4d4575...2b8886 )
by Xeriab
02:40
created

Json::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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Konfig
4
 *
5
 * Yet another simple configuration loader library.
6
 *
7
 * @author  Xeriab Nabil (aka KodeBurner) <[email protected]>
8
 * @license https://raw.github.com/xeriab/konfig/master/LICENSE MIT
9
 * @link    https://xeriab.github.io/projects/konfig
10
 */
11
12
namespace Exen\Konfig\FileParser;
13
14
use Exen\Konfig\Exception\ParseException;
15
16
class Json extends AbstractFileParser
17
{
18
    /**
19
     * {@inheritDoc}
20
     * Loads a JSON file as an array
21
     *
22
     * @throws ParseException If there is an error parsing JSON file
23
     * @since 0.1
24
     */
25 6
    public function parse($path)
26
    {
27 6
        $data = json_decode(file_get_contents($path), true);
28
29 6
        if (function_exists('json_last_error_msg')) {
30 4
            $error_message = json_last_error_msg();
31 4
        } else {
32 2
            $error_message = 'Syntax error';
33
        }
34
35 6
        if (json_last_error() !== JSON_ERROR_NONE) {
36 3
            throw new ParseException([
37 3
                'message' => $error_message,
38 3
                'type'    => json_last_error(),
39 3
                'file'    => $path,
40 3
            ]);
41
        }
42
43 3
        return $data;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49 3
    public function getSupportedFileExtensions()
50
    {
51 3
        return ['json'];
52
    }
53
}
54
55
#: END OF ./src/FileParser/Json.php FILE
56