Statement::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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