Completed
Push — master ( b31514...603a9f )
by Changwan
06:16
created

Descriptor::createInstance()   C

Complexity

Conditions 17
Paths 9

Size

Total Lines 60
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 26.1019

Importance

Changes 0
Metric Value
cc 17
eloc 38
nc 9
nop 1
dl 0
loc 60
ccs 26
cts 38
cp 0.6842
crap 26.1019
rs 6.2661
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Wandu\DI;
3
4
use Wandu\DI\ContainerFluent;
5
6
class Descriptor implements ContainerFluent 
7
{
8
    /** @var array */
9
    public $assigns = [];
10
    
11
    /** @var array */
12
    public $wires = [];
13
    
14
    /** @var callable[] */
15
    public $afterHandlers = [];
16
17
    /** @var bool */
18
    public $factory = false;
19
    
20
    /** @var bool */
21
    public $frozen = false;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 7
    public function assign(string $paramName, $target): ContainerFluent
27
    {
28 7
        $this->assigns[$paramName] = $target;
29 7
        return $this;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 3
    public function assignMany(array $params = []): ContainerFluent
36
    {
37 3
        $this->assigns = $params + $this->assigns;
38 3
        return $this;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 8
    public function wire(string $propertyName, $target): ContainerFluent
45
    {
46 8
        $this->wires[$propertyName] = $target;
47 8
        return $this;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 3
    public function wireMany(array $properties): ContainerFluent
54
    {
55 3
        $this->wires = $properties + $this->wires;
56 3
        return $this;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 4
    public function after(callable $handler): ContainerFluent
63
    {
64 4
        $this->afterHandlers[] = $handler;
65 4
        return $this;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 5
    public function factory(): ContainerFluent
72
    {
73 5
        $this->factory = true;
74 5
        return $this;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 92
    public function freeze(): ContainerFluent
81
    {
82 92
        $this->frozen = true;
83 92
        return $this;
84
    }
85
}
86