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

Php   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 35.9 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 14
loc 39
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 14 14 2
A loadSettings() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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