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

FilesystemConfigurationProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 65
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getConfigurations() 0 6 1
A getResources() 0 6 1
A processFileResources() 0 10 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\Provider;
13
14
use Sylius\Bundle\ThemeBundle\Configuration\Loader\ConfigurationLoaderInterface;
15
use Sylius\Bundle\ThemeBundle\Locator\FileLocatorInterface;
16
use Symfony\Component\Config\Resource\FileResource;
17
18
/**
19
 * @author Kamil Kokot <[email protected]>
20
 */
21
final class FilesystemConfigurationProvider implements ConfigurationProviderInterface
22
{
23
    /**
24
     * @var FileLocatorInterface
25
     */
26
    private $fileLocator;
27
28
    /**
29
     * @var ConfigurationLoaderInterface
30
     */
31
    private $loader;
32
33
    /**
34
     * @var string
35
     */
36
    private $configurationFilename;
37
38
    /**
39
     * @param FileLocatorInterface $fileLocator
40
     * @param ConfigurationLoaderInterface $loader
41
     * @param string $configurationFilename
42
     */
43
    public function __construct(FileLocatorInterface $fileLocator, ConfigurationLoaderInterface $loader, $configurationFilename)
44
    {
45
        $this->fileLocator = $fileLocator;
46
        $this->loader = $loader;
47
        $this->configurationFilename = $configurationFilename;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getConfigurations()
54
    {
55
        return $this->processFileResources(function ($file) {
56
            return $this->loader->load($file);
57
        });
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getResources()
64
    {
65
        return $this->processFileResources(function ($file) {
66
            return new FileResource($file);
67
        });
68
    }
69
70
    /**
71
     * @param callable $callback
72
     *
73
     * @return array
74
     */
75
    private function processFileResources(callable $callback)
76
    {
77
        try {
78
            $configurationFiles = $this->fileLocator->locateFilesNamed($this->configurationFilename);
79
80
            return array_map($callback, $configurationFiles);
81
        } catch (\InvalidArgumentException $exception) {
82
            return [];
83
        }
84
    }
85
}
86