Statement::toString()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3
Metric Value
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.4286
cc 3
eloc 8
nc 3
nop 1
crap 3
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