DefinitionFactory::create()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 16
ccs 8
cts 8
cp 1
crap 4
rs 9.7333
c 0
b 0
f 0
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