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

OrComposite   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 40%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addOr() 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 OrComposite 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 addOr(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 true;
44
            }
45
        }
46
47 1
        return false;
48
    }
49
50
    /**
51
     * @see MetaborStd.NamedInterface::getName()
52
     */
53
    public function getName()
54
    {
55
        return '(' . implode(' or ', $this->conditions->getNames()) . ')';
56
    }
57
}
58