Completed
Pull Request — master (#10)
by Tomáš
02:47
created

SiteConfigurationFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
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