Completed
Push — master ( dd3765...8c44c3 )
by Pablo
07:02
created

ConfigurationFileReader::getDefaultConfigData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace PhpGitHooks\Module\Configuration\Infrastructure\Persistence\Disk;
4
5
use PhpGitHooks\Module\Configuration\Domain\Config;
6
use PhpGitHooks\Module\Configuration\Model\ConfigurationFileReaderInterface;
7
use PhpGitHooks\Module\Configuration\Service\ConfigFactory;
8
use Symfony\Component\Yaml\Yaml;
9
10
class ConfigurationFileReader implements ConfigurationFileReaderInterface
11
{
12
    const CONFIG_FILE = 'php-git-hooks.yml';
13
14
    /**
15
     * @return Config
16
     */
17
    public function getData()
18
    {
19
        $data = true === $this->configFileExists() ? $this->getConfigData() : [];
20
21
        return ConfigFactory::fromArray($data);
22
    }
23
24
    /**
25
     * @return bool
26
     */
27
    private function configFileExists()
28
    {
29
        return file_exists(self::CONFIG_FILE);
30
    }
31
32
    /**
33
     * @return array
34
     */
35
    private function getConfigData()
36
    {
37
        return Yaml::parse(file_get_contents(self::CONFIG_FILE));
38
    }
39
}
40