Completed
Pull Request — master (#12)
by Tomáš
06:06 queued 03:15
created

SiteConfigurationFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 31
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 8 2
A getConfigFile() 0 6 1
1
<?php
2
3
/*
4
 * This file is a part of Sculpin.
5
 *
6
 * (c) Dragonfly Development Inc.
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 Symplify\PHP7_Sculpin\Configuration;
13
14
use Dflydev\DotAccessConfiguration\Configuration;
15
use Dflydev\DotAccessConfiguration\ConfigurationInterface;
16
17
final class SiteConfigurationFactory
18
{
19
    /**
20
     * @var string
21
     */
22
    private $rootDir;
23
24 2
    public function __construct(string $rootDir)
25
    {
26 2
        $this->rootDir = $rootDir;
27 2
    }
28
29 2
    public function create() : ConfigurationInterface
30
    {
31 2
        if (file_exists($file = $this->rootDir.'/config/sculpin_site.yml')) {
32 1
            return $this->getConfigFile($file);
33
        }
34
35 1
        return new Configuration();
36
    }
37
38
    /**
39
     * Get an instance of the Configuration() class from the given file.
40
     */
41 1
    private function getConfigFile(string $configFile) : ConfigurationInterface
42
    {
43 1
        $builder = new YamlFileConfigurationBuilder($configFile);
44
45 1
        return $builder->build();
46
    }
47
}
48