Autowire::resolve()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 1
cts 1
cp 1
crap 1
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
8
namespace Spiral\Core\Container;
9
10
use Spiral\Core\FactoryInterface;
11
12
/**
13
 * Provides ability to delegate option to container.
14
 */
15
final class Autowire
16
{
17
    /**
18
     * Delegation target
19
     *
20
     * @var mixed
21
     */
22
    private $alias;
23
24
    /**
25
     * @var array
26
     */
27
    private $parameters = [];
28
29
    /**
30
     * Autowire constructor.
31
     *
32
     * @param string $alias
33
     * @param array  $parameters
34
     */
35 2
    public function __construct(string $alias, array $parameters = [])
36
    {
37 2
        $this->alias = $alias;
38 2
        $this->parameters = $parameters;
39 2
    }
40
41
    /**
42
     * @param FactoryInterface $factory
43
     * @param array            $parameters Context specific parameters (always prior to declared
44
     *                                     ones).
45
     *
46
     * @return mixed
47
     *
48
     * @throws \Spiral\Core\Exceptions\Container\AutowireException  No entry was found for this
49
     *                                                         identifier.
50 1
     * @throws \Interop\Container\Exception\ContainerException Error while retrieving the entry.
51
     */
52 1
    public function resolve(
53
        FactoryInterface $factory,
54
        array $parameters = []
55
    ) {
56
        return $factory->make($this->alias, $parameters + $this->parameters);
57
    }
58
59
    /**
60
     * @param $an_array
61
     *
62
     * @return static
63
     */
64
    public static function __set_state($an_array)
65
    {
66
        return new static($an_array['alias'], $an_array['parameters']);
67
    }
68
}