Completed
Pull Request — master (#25)
by
unknown
05:59 queued 04:47
created

AndComposite::checkCondition()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
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
        }
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