Completed
Push — master ( 0e678b...8a4e34 )
by Filipe
02:44
created

Php::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
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 $filePath;
26
27 12
    use CommonDriverMethods;
28
29 12
    /**
30 12
     * Creates a Php configuration driver
31 3
     *
32 3
     * @param $filePath
33 3
     */
34 View Code Duplication
    public function __construct($filePath)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
53
    {
54
        ob_start();
55
        $this->data = include $this->filePath;
56
        ob_end_clean();
57
    }
58
}
59