DefinitionLoader::load()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 7
Ratio 43.75 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 7
loc 16
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 2
nop 1
crap 3
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