ConfigurationLoader::getFilePath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
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 4
    public function load()
32
    {
33 4
        $filename = $this->getFilePath();
34 4
        if (!file_exists($filename) || !is_readable($filename)) {
35
            throw new RuntimeException('The configuration YAML file does not exist!');
36
        }
37
38 4
        return Yaml::parse(file_get_contents($filename));
39
    }
40
41
    /**
42
     * Return the path to the configuration file
43
     *
44
     * @return string
45
     */
46 5
    public function getFilePath()
47
    {
48 5
        return CONSOLE_BASE_DIR . '/' . self::CONFIGURATION_FILE;
49
    }
50
}
51