Completed
Pull Request — master (#12)
by Tomáš
06:06 queued 03:15
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\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