Json   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 18 3
1
<?php
2
3
namespace TheIconic\Config\Parser;
4
5
use TheIconic\Config\Exception\ParserException;
6
7
/**
8
 * config file parser for ini files
9
 *
10
 * @package Shared\Helper\Config\Parser
11
 */
12
class Json extends AbstractParser
13
{
14
    /**
15
     * parses a json config file containing a config array
16
     *
17
     * @param string $file
18
     * @return array
19
     */
20
    public function parse($file)
21
    {
22
        $config = json_decode(file_get_contents($file), true);
23
24
        if (!is_array($config)) {
25
            $error = json_last_error();
26
27
            if ($error === JSON_ERROR_NONE) {
28
                $message = 'Invalid configuration format';
29
            } else {
30
                $message = json_last_error_msg();
31
            }
32
33
            throw new ParserException(sprintf('Couldn\'t parse config file %s: %s', $file, $message));
34
        }
35
36
        return $config;
37
    }
38
}
39