CurrencyInfoSource::fromFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace VinaiKopp\CurrencyInfo\Build;
4
5
class CurrencyInfoSource
6
{
7
    /**
8
     * @var array[]
9
     */
10
    private $source;
11
12
    /**
13
     * @param array[] $source
14
     */
15 3
    public function __construct(array $source)
16
    {
17 3
        $this->source = $source;
18 3
    }
19
20
    /**
21
     * @param string $fileName
22
     * @return CurrencyInfoSource
23
     */
24 1
    public static function fromFile($fileName)
25
    {
26 1
        return self::fromJson(file_get_contents($fileName));
27
    }
28
29
    /**
30
     * @param string $json
31
     * @return CurrencyInfoSource
32
     */
33 3
    public static function fromJson($json)
34
    {
35 3
        $source = json_decode($json, true);
36 3
        if (json_last_error() !== \JSON_ERROR_NONE) {
37 1
            throw new \InvalidArgumentException('Input has to be a JSON encoded currency info object');
38
        }
39 2
        return new self($source);
40
    }
41
42 3
    public function get()
43
    {
44 3
        return $this->source;
45
    }
46
}
47