Completed
Push — master ( fab006...1c4cac )
by Miloš
01:47
created

DefinitionFactory::create()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 16
ccs 7
cts 8
cp 0.875
crap 4.0312
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace Laganica\Di\Definition;
4
5
use Closure;
6
use Laganica\Di\Exception\InvalidDefinitionException;
7
8
/**
9
 * Class DefinitionFactory
10
 *
11
 * @package Laganica\Di\Definition
12
 */
13
class DefinitionFactory implements DefinitionFactoryInterface
14
{
15
    /**
16
     * @inheritDoc
17
     */
18 7
    public function create($definition): DefinitionInterface
19
    {
20 7
        if ($definition instanceof DefinitionInterface) {
21 5
            return $definition;
22
        }
23
24 2
        if ($definition instanceof Closure) {
25 1
            return new ClosureDefinition($definition);
26
        }
27
28 1
        if (is_string($definition)) {
29 1
            return new ClassDefinition($definition);
30
        }
31
32
        throw InvalidDefinitionException::create($definition);
33
    }
34
}
35