IniLoader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 7
c 5
b 1
f 0
lcom 1
cbo 1
dl 39
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
B load() 26 26 6

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
 * INI file loader.
4
 *
5
 * @package SugiPHP.Config
6
 * @author  Plamen Popov <[email protected]>
7
 * @license http://opensource.org/licenses/mit-license.php (MIT License)
8
 */
9
10
namespace SugiPHP\Config;
11
12 View Code Duplication
class IniLoader implements LoaderInterface
0 ignored issues
show
Duplication introduced by
This class 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...
13
{
14
    protected $locator;
15
16
    public function __construct(LocatorInterface $locator = null)
17
    {
18
        $this->locator = $locator;
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function load($resource)
25
    {
26
        // check the extension. If it's not provided we'll add .ini
27
        if (pathinfo($resource, PATHINFO_EXTENSION) === "") {
28
            $resource .= ".ini";
29
        }
30
31
        $file = false;
32
33
        if ($this->locator) {
34
            // pass it to the locator (if set) and than include the file
35
            $file = $this->locator->locate($resource);
36
        } elseif (is_file($resource) && is_readable($resource)) {
37
            // check if the $resource is a real file and include it
38
            $file = $resource;
39
        }
40
41
        if ($file) {
42
            // By setting the process_sections parameter (second param) to TRUE, you get a
43
            // multidimensional array, with the section names and settings included.
44
            // The default for process_sections is FALSE
45
            return parse_ini_file($file, true);
46
        }
47
48
        return null;
49
    }
50
}
51