DefinitionFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 8
cts 8
cp 1
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
/**
4
 * This file is part of the Container package.
5
 *
6
 * Copyright (c) Miloš Đurić <[email protected]>
7
 *
8
 * For full copyright and license information, please refer to the LICENSE file,
9
 * located at the package root folder.
10
 */
11
12
namespace Laganica\Di\Definition;
13
14
use Closure;
15
use Laganica\Di\Exception\InvalidDefinitionException;
16
17
/**
18
 * Class DefinitionFactory
19
 *
20
 * @package Laganica\Di\Definition
21
 */
22
class DefinitionFactory implements DefinitionFactoryInterface
23
{
24
    /**
25
     * @inheritDoc
26
     */
27 18
    public function create($definition): DefinitionInterface
28
    {
29 18
        if ($definition instanceof DefinitionInterface) {
30 15
            return $definition;
31
        }
32
33 5
        if ($definition instanceof Closure) {
34 1
            return new ClosureDefinition($definition);
35
        }
36
37 4
        if (is_string($definition)) {
38 3
            return new ClassDefinition($definition);
39
        }
40
41 1
        throw InvalidDefinitionException::create($definition);
42
    }
43
}
44