Completed
Pull Request — master (#10)
by Tomáš
02:47
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\SiteConfiguration;
13
14
use Dflydev\DotAccessConfiguration\Configuration;
15
use Dflydev\DotAccessConfiguration\ConfigurationInterface;
16
use Symplify\PHP7_Sculpin\Configuration\YamlFileConfigurationBuilder;
17
18
final class SiteConfigurationFactory
19
{
20
    /**
21
     * @var string
22
     */
23
    private $rootDir;
24
25 2
    public function __construct(string $rootDir)
26
    {
27 2
        $this->rootDir = $rootDir;
28 2
    }
29
30 2
    public function create() : Configuration
31
    {
32 2
        if (file_exists($file = $this->rootDir.'/config/sculpin_site.yml')) {
33 1
            return $this->getConfigFile($file);
34
        }
35
36 1
        return new Configuration();
37
    }
38
39
    /**
40
     * Get an instance of the Configuration() class from the given file.
41
     */
42 1
    private function getConfigFile(string $configFile) : ConfigurationInterface
43
    {
44 1
        $builder = new YamlFileConfigurationBuilder([$configFile]);
45
46 1
        return $builder->build();
47
    }
48
}
49