Php::loadSettings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of Configuration
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Configuration\Driver;
11
12
use Slick\Configuration\ConfigurationInterface;
13
use Slick\Configuration\Exception\ParserErrorException;
14
15
/**
16
 * Php Configuration driver
17
 *
18
 * @package Slick\Configuration\Driver
19
 */
20
class Php implements ConfigurationInterface
21
{
22
    /**
23
     * @var string
24
     */
25
    private string $filePath;
26
27 12
    use CommonDriverMethods;
28
29 12
    /**
30 12
     * Creates a Php configuration driver
31 3
     *
32 3
     * @param string $filePath
33 3
     */
34
    public function __construct(string $filePath)
35 9
    {
36
        $this->checkFile($filePath);
37
38
        $this->filePath = $filePath;
39
        $this->loadSettings();
40
41
        if (!is_array($this->data)) {
42
            throw new ParserErrorException(
43
                "Configuration file $this->filePath could not be parse as an array. ".
44
                "PHP Settings file should be a script that returns an array."
45
            );
46
        }
47
    }
48
49
    /**
50
     * Loads settings from php array in file
51
     */
52
    private function loadSettings(): void
53
    {
54
        ob_start();
55
        $this->data = include $this->filePath;
56
        ob_end_clean();
57
    }
58
}
59