CurrencyInfoSource   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 42
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromFile() 0 4 1
A fromJson() 0 8 2
A get() 0 4 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