JsonLoader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 8
c 2
b 0
f 0
dl 0
loc 32
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 3 1
A __construct() 0 8 5
1
<?php
2
3
namespace ComposerRequireChecker;
4
5
use ComposerRequireChecker\Exception\InvalidJsonException;
6
use ComposerRequireChecker\Exception\NotReadableException;
7
8
class JsonLoader
9
{
10
11
    /**
12
     * @var mixed
13
     */
14
    private $data;
15
16
    /**
17
     * @param string $path
18
     * @throws InvalidJsonException
19
     * @throws NotReadableException
20
     * @internal
21
     */
22 11
    public function __construct($path)
23
    {
24 11
        if (!is_readable($path) || ($content = file_get_contents($path)) === false) {
25 1
            throw new NotReadableException('unable to read ' . $path);
26
        }
27 10
        $this->data = json_decode($content, true);
28 10
        if ($this->data === null && JSON_ERROR_NONE !== json_last_error()) {
29 1
            throw new InvalidJsonException('error parsing ' . $path . ': ' . json_last_error_msg());
30
        }
31 9
    }
32
33
    /**
34
     * @internal
35
     * @return mixed
36
     */
37 9
    public function getData()
38
    {
39 9
        return $this->data;
40
    }
41
}
42