Completed
Push — master ( 01b890...8110dc )
by Robbie
01:11
created

ConfigurationLoader::getFilePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace SilverLeague\Console\Framework\Loader;
4
5
use RuntimeException;
6
use SilverLeague\Console\Framework\ConsoleBase;
7
use Symfony\Component\Yaml\Yaml;
8
9
/**
10
 * The Configuration Loader is reponsible for loading the core configuration YAML file, and merging in any
11
 * other configuration files from other locations
12
 *
13
 * @package silverstripe-console
14
 * @author  Robbie Averill <[email protected]>
15
 */
16
class ConfigurationLoader extends ConsoleBase
17
{
18
    /**
19
     * The configuration file name to look for
20
     *
21
     * @var string
22
     */
23
    const CONFIGURATION_FILE = 'console.yml';
24
25
    /**
26
     * Load the YAML configuration for the application and return it
27
     *
28
     * @return array
29
     * @throws RuntimeException If the filecould not be loaded
30
     */
31 2
    public function load()
32
    {
33 2
        $filename = $this->getFilePath();
34 2
        if (!file_exists($filename) || !is_readable($filename)) {
35
            throw new RuntimeException('The configuration YAML file does not exist!');
36
        }
37
38 2
        return Yaml::parse($filename);
39
    }
40
41
    /**
42
     * Return the path to the configuration file
43
     *
44
     * @return string
45
     */
46 3
    public function getFilePath()
47
    {
48 3
        return CONSOLE_BASE_DIR . '/' . self::CONFIGURATION_FILE;
49
    }
50
}
51