Completed
Push — master ( baff27...3a9c47 )
by Daniel
02:56
created

Loader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 41
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 12 2
1
<?php
2
/**
3
 * This file is part of the Commander project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Commander\Config;
9
10
use GravityMedia\Commander\Config;
11
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
12
13
/**
14
 * Config loader class.
15
 *
16
 * @package GravityMedia\Commander\Config
17
 */
18
class Loader
19
{
20
    /**
21
     * The serializer.
22
     *
23
     * @var Serializer
24
     */
25
    protected $serializer;
26
27
    /**
28
     * Create config loader object.
29
     *
30
     * @param Serializer $serializer
31
     */
32 4
    public function __construct(Serializer $serializer)
33
    {
34 4
        $this->serializer = $serializer;
35 4
    }
36
37
    /**
38
     * Load config.
39
     *
40
     * @param string $filename
41
     *
42
     * @return Config
43
     *
44
     * @throws \InvalidArgumentException
45
     */
46 4
    public function load($filename)
47
    {
48 4
        $data = file_get_contents($filename);
49
50
        try {
51 4
            $config = $this->serializer->deserialize($data, Config::class, 'json');
52 3
        } catch (UnexpectedValueException $exception) {
53 2
            throw new \InvalidArgumentException('Invalid configuration file', 0, $exception);
54
        }
55
56 2
        return $config;
57
    }
58
}
59