Completed
Pull Request — develop (#79)
by
unknown
44:24 queued 32:59
created

Json::getSupportedExtensions()   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 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
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
namespace Noodlehaus\FileParser;
4
5
use Noodlehaus\Exception\ParseException;
6
7
/**
8
 * JSON file parser
9
 *
10
 * @package    Config
11
 * @author     Jesus A. Domingo <[email protected]>
12
 * @author     Hassan Khan <[email protected]>
13
 * @link       https://github.com/noodlehaus/config
14
 * @license    MIT
15
 */
16
class Json implements FileParserInterface
17
{
18
    /**
19
     * {@inheritDoc}
20
     * Loads a JSON file as an array
21
     *
22
     * @throws ParseException If there is an error parsing the JSON file
23
     */
24 6
    public function parse($path)
25
    {
26 6
        $data = json_decode(file_get_contents($path), true);
27
28 6
        if (json_last_error() !== JSON_ERROR_NONE) {
29 3
            $error = array(
30 3
                'message' => 'Syntax error',
31 1
                'type'    => json_last_error(),
32 1
                'file'    => $path,
33
            );
34
            throw new ParseException($error);
35 3
        }
36 3
37 3
        return $data;
38 3
    }
39 3
40
    /**
41
     * {@inheritDoc}
42 3
     */
43
    public function getSupportedExtensions()
44
    {
45
        return array('json');
46
    }
47
}
48