Statement   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 39
wmc 6
lcom 1
cbo 2
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toString() 0 18 3
A wrapWithParenthese() 0 4 1
A isEmpty() 0 4 1
1
<?php
2
3
namespace Muffin\Conditions;
4
5
use Muffin\Escaper;
6
use Muffin\Condition;
7
use Muffin\Query;
8
9
class Statement extends AbstractCondition
10
{
11
    private
12
        $statement;
13
14 10
    public function __construct($statement)
15
    {
16 10
        $this->statement = $statement;
17 10
    }
18
19 5
    public function toString(Escaper $escaper)
20
    {
21 5
        if($this->isEmpty())
22 5
        {
23 2
            return '';
24
        }
25
26 3
        $statement = $this->statement;
27
28 3
        if($this->statement instanceof Query)
29 3
        {
30 2
            $this->statement->setEscaper($escaper);
31
32 2
            $statement = $this->wrapWithParenthese($this->statement->toString());
33 2
        }
34
35 3
        return (string) $statement;
36
    }
37
38 2
    private function wrapWithParenthese($value)
39
    {
40 2
        return sprintf('(%s)', $value);
41
    }
42
43 10
    public function isEmpty()
44
    {
45 10
        return empty($this->statement);
46
    }
47
}
48