AbstractCompositeCondition   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 46
wmc 8
lcom 1
cbo 2
ccs 21
cts 21
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A toString() 0 14 3
A isEmpty() 0 4 2
A buildPartCondition() 0 11 2
buildCondition() 0 1 ?
1
<?php
2
3
namespace Muffin\Conditions\Binaries;
4
5
use Muffin\Conditions\CompositeCondition;
6
use Muffin\Condition;
7
use Muffin\Escaper;
8
use Muffin\Conditions\AbstractCondition;
9
10
abstract class AbstractCompositeCondition extends AbstractCondition implements CompositeCondition
11
{
12
    protected
13
        $leftCondition,
14
        $rightCondition;
15
16 45
    public function __construct(Condition $leftCondition, Condition $rightCondition)
17
    {
18 45
        $this->leftCondition = $leftCondition;
19 45
        $this->rightCondition = $rightCondition;
20 45
    }
21
22 41
    public function toString(Escaper $escaper)
23
    {
24 41
        if($this->leftCondition->isEmpty())
25 41
        {
26 11
            return $this->rightCondition->toString($escaper);
27
        }
28
29 37
        if($this->rightCondition->isEmpty())
30 37
        {
31 10
            return $this->leftCondition->toString($escaper);
32
        }
33
34 33
        return $this->buildCondition($escaper);
35
    }
36
37 40
    public function isEmpty()
38
    {
39 40
        return $this->leftCondition->isEmpty() && $this->rightCondition->isEmpty();
40
    }
41
42 33
    protected function buildPartCondition(Condition $condition, Escaper $escaper)
43
    {
44 33
        $partCondition = $condition->toString($escaper);
45
46 33
        if($condition instanceof CompositeCondition)
47 33
        {
48 23
            $partCondition = sprintf('(%s)', $partCondition);
49 23
        }
50
51 33
        return $partCondition;
52
    }
53
54
    abstract protected function buildCondition(Escaper $escaper);
55
}
56