Completed
Branch master (755019)
by Oliver
12:48 queued 05:47
created

AndComposite::addAnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 1.0156
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
    public function __construct(ConditionInterface $condition)
19
    {
20
        $this->conditions = new NamedCollection();
21
        $this->conditions->add($condition);
22
    }
23
24
    /**
25
     * @param ConditionInterface $condition
26
     *
27
     * @return $this
28
     */
29 1
    public function addAnd(ConditionInterface $condition)
30
    {
31
        $this->conditions->add($condition);
32
33 1
        return $this;
34 1
    }
35
36
    /**
37
     * @see MetaborStd\Statemachine.ConditionInterface::checkCondition()
38
     */
39 1
    public function checkCondition($subject, \ArrayAccess $context)
40
    {
41
        foreach ($this->conditions as $condition) {
42
            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
    public function getName()
54
    {
55
        return '(' . implode(' and ', $this->conditions->getNames()) . ')';
56
    }
57
}
58