Completed
Branch 2.x (dc1b30)
by Akihito
02:25
created

Untarget::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 11
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
ccs 10
cts 10
cp 1
crap 2
rs 9.4285
1
<?php
2
/**
3
 * This file is part of the Ray.Di package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\Di;
8
9
class Untarget
10
{
11
    /**
12
     * @var \ReflectionClass
13
     */
14
    private $class;
15
16
    /**
17
     * @var string
18
     */
19
    private $scope = Scope::PROTOTYPE;
20
21
    /**
22
     * @param string $class
23
     */
24 27
    public function __construct($class)
25
    {
26 27
        $this->class = new \ReflectionClass($class);
27 27
    }
28
29 1
    public function setScope($scope)
30
    {
31 1
        $this->scope = $scope;
32 1
    }
33
34
    /**
35
     * Bind untargeted binding
36
     *
37
     * @param Container $container
38
     * @param Bind      $bind
39
     */
40 13
    public function __invoke(Container $container, Bind $bind)
41
    {
42 13
        $bound = (new DependencyFactory)->newAnnotatedDependency($this->class);
43 13
        $bound->setScope($this->scope);
44 13
        $bind->setBound($bound);
45 13
        $container->add($bind);
46 13
        $constructor = $this->class->getConstructor();
47 13
        if ($constructor) {
48 8
            (new UntargetedBind)->__invoke($container, $constructor);
49 8
        }
50 13
    }
51
}
52