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

DefinitionFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 16 4
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