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

Json   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 3
c 4
b 1
f 1
lcom 0
cbo 1
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 15 2
A getSupportedExtensions() 0 4 1
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