DefinitionLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 28 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 7 16 3

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
namespace Assimtech\Tempo\Loader;
4
5
use Assimtech\Tempo\Definition;
6
use RuntimeException;
7
8
class DefinitionLoader extends AbstractLoader
9
{
10
    /**
11
     * @param string $path The path to a php file that constructs and returns an \Assimtech\Tempo\Definition
12
     *      defaults to 'tempo/definition.php'
13
     * @return \Assimtech\Tempo\Definition
14
     * @throws \RuntimeException
15
     */
16 4
    public function load($path)
17
    {
18 4
        $this->validatePath($path);
19
20 2
        $definition = require $path;
21
22 2 View Code Duplication
        if (!$definition instanceof Definition) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
23 1
            throw new RuntimeException(sprintf(
24 1
                "%s must return an instance of \Assimtech\Tempo\Definition (%s returned)",
25 1
                $path,
26 1
                is_object($definition) ? get_class($definition) : gettype($definition)
27 1
            ));
28
        }
29
30 1
        return $definition;
31
    }
32
}
33