Completed
Push — master ( db026b...56b106 )
by Oliver
04:09 queued 02:28
created

AndComposite   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 50
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addAnd() 0 6 1
A checkCondition() 0 10 3
A getName() 0 4 1
1
<?php
2
3
namespace Metabor\Statemachine\Condition;
4
5
use Metabor\NamedCollection;
6
use MetaborStd\Statemachine\ConditionInterface;
7
8
class AndComposite implements ConditionInterface
9
{
10
    /**
11
     * @var NamedCollection|ConditionInterface[]
12
     */
13
    private $conditions;
14
15
    /**
16
     * @param ConditionInterface $condition
17
     */
18 2
    public function __construct(ConditionInterface $condition)
19
    {
20 2
        $this->conditions = new NamedCollection();
21 2
        $this->conditions->add($condition);
22 2
    }
23
24
    /**
25
     * @param ConditionInterface $condition
26
     *
27
     * @return $this
28
     */
29 1
    public function addAnd(ConditionInterface $condition)
30
    {
31 1
        $this->conditions->add($condition);
32
33 1
        return $this;
34
    }
35
36
    /**
37
     * @see MetaborStd\Statemachine.ConditionInterface::checkCondition()
38
     */
39 1
    public function checkCondition($subject, \ArrayAccess $context)
40
    {
41 1
        foreach ($this->conditions as $condition) {
42 1
            if (!$condition->checkCondition($subject, $context)) {
43 1
                return false;
44
            }
45 1
        }
46
47 1
        return true;
48
    }
49
50
    /**
51
     * @see MetaborStd.NamedInterface::getName()
52
     */
53 1
    public function getName()
54
    {
55 1
        return '(' . implode(' and ', $this->conditions->getNames()) . ')';
56
    }
57
}
58