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

Untarget   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 43
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setScope() 0 4 1
A __invoke() 0 11 2
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