NativeLoader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
B load() 23 23 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
 * PHP 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 NativeLoader 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 .php
27
        if (pathinfo($resource, PATHINFO_EXTENSION) === "") {
28
            $resource .= ".php";
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
            return include $file;
43
        }
44
45
        return null;
46
    }
47
}
48