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

SetterMethods   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 6 2
A __invoke() 0 7 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
final class SetterMethods
10
{
11
    /**
12
     * @var SetterMethod[]
13
     */
14
    private $setterMethods;
15
16 51
    public function __construct(array $setterMethods)
17
    {
18 51
        $this->setterMethods = $setterMethods;
19 51
    }
20
21
    /**
22
     * @param SetterMethod $setterMethod
23
     */
24 25
    public function add(SetterMethod $setterMethod = null)
25
    {
26 25
        if ($setterMethod) {
27 10
            $this->setterMethods[] = $setterMethod;
28 10
        }
29 25
    }
30
31
    /**
32
     * @param object    $instance
33
     * @param Container $container
34
     *
35
     * @throws Exception\Unbound
36
     * @throws \Exception
37
     */
38 48
    public function __invoke($instance, Container $container)
39
    {
40 48
        foreach ($this->setterMethods as $setterMethod) {
41
            /* @var SetterMethod $setterMethod */
42 18
            $setterMethod->__invoke($instance, $container);
43 47
        }
44 47
    }
45
}
46