ConfigReader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A readToArray() 0 19 3
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Package;
7
8
class ConfigReader
9
{
10
    /**
11
     * @var \Seld\JsonLint\JsonParser
12
     */
13
    private $jsonDecoder;
14
15
    public function __construct()
16
    {
17
        $this->jsonDecoder = new \Seld\JsonLint\JsonParser();
18
    }
19
20
    public function readToArray($source)
21
    {
22
        if (!file_exists($source)) {
23
            throw new \Vaimo\ComposerPatches\Exceptions\ReadException(
24
                sprintf('File not found: %s', $source)
25
            );
26
        }
27
28
        $sourceData = file_get_contents($source);
29
30
        if ($sourceData === false) {
31
            throw new \Vaimo\ComposerPatches\Exceptions\ReadException(
32
                sprintf('Failed to retrieve contents: %s', $source)
33
            );
34
        }
35
36
        return $this->jsonDecoder->parse(
37
            $sourceData,
38
            \Seld\JsonLint\JsonParser::PARSE_TO_ASSOC
39
        );
40
    }
41
}
42