Completed
Push — master ( 79d213...eeff33 )
by Kamil
23:15
created

JsonFileConfigurationLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 11 1
A assertFileExists() 0 9 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ThemeBundle\Configuration\Loader;
13
14
use Sylius\Bundle\ThemeBundle\Filesystem\FilesystemInterface;
15
16
/**
17
 * @author Kamil Kokot <[email protected]>
18
 */
19
final class JsonFileConfigurationLoader implements ConfigurationLoaderInterface
20
{
21
    /**
22
     * @var FilesystemInterface
23
     */
24
    private $filesystem;
25
26
    /**
27
     * @param FilesystemInterface $filesystem
28
     */
29
    public function __construct(FilesystemInterface $filesystem)
30
    {
31
        $this->filesystem = $filesystem;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function load($path)
38
    {
39
        $this->assertFileExists($path);
40
41
        $contents = $this->filesystem->getFileContents($path);
42
43
        return array_merge(
44
            ['path' => dirname($path)],
45
            json_decode($contents, true)
46
        );
47
    }
48
49
    /**
50
     * @param string $path
51
     */
52
    private function assertFileExists($path)
53
    {
54
        if (!$this->filesystem->exists($path)) {
55
            throw new \InvalidArgumentException(sprintf(
56
                'Given file "%s" does not exist!',
57
                $path
58
            ));
59
        }
60
    }
61
}
62