Total Complexity | 9 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Coverage | 33.33% |
Changes | 0 |
1 | <?php |
||
14 | final class PackageConfiguration |
||
15 | { |
||
16 | /** @var array */ |
||
17 | private $data = []; |
||
18 | |||
19 | 7 | public function __construct(array $data) |
|
28 | 7 | } |
|
29 | |||
30 | public static function buildFromPath(string $path): self |
||
31 | { |
||
32 | if (!$json = file_get_contents($path)) { |
||
33 | throw new \RuntimeException(sprintf('File "%s" is not readable')); |
||
34 | } |
||
35 | |||
36 | return self::buildFromJson($json); |
||
37 | } |
||
38 | |||
39 | public static function buildFromJson(string $json): self |
||
40 | { |
||
41 | if (!$data = json_decode($json, true)) { |
||
42 | throw new \RuntimeException('Impossible to decode JSON string as array'); |
||
43 | } |
||
44 | |||
45 | return new self($data); |
||
46 | } |
||
47 | |||
48 | 3 | public function _toArray(): array |
|
49 | { |
||
50 | 3 | return $this->data; |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * |
||
55 | * @param string $name |
||
56 | * @return string|array |
||
57 | */ |
||
58 | public function __get($name) |
||
67 | } |
||
68 | } |
||
69 |