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%

Importance

Changes 0
Metric Value
dl 0
loc 39
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2
ccs 15
cts 15
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toString() 0 18 3
A wrapWithParenthesis() 0 4 1
A isEmpty() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Conditions;
6
7
use Puzzle\QueryBuilder\Escaper;
8
use Puzzle\QueryBuilder\Query;
9
10
class Statement extends AbstractCondition
11
{
12
    private
13
        $statement;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $statement.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
14
15 10
    public function __construct($statement)
16
    {
17 10
        $this->statement = $statement;
18 10
    }
19
20 5
    public function toString(Escaper $escaper): string
21
    {
22 5
        if($this->isEmpty())
23
        {
24 2
            return '';
25
        }
26
27 3
        $statement = $this->statement;
28
29 3
        if($this->statement instanceof Query)
30
        {
31 2
            $this->statement->setEscaper($escaper);
32
33 2
            $statement = $this->wrapWithParenthesis($this->statement->toString());
34
        }
35
36 3
        return (string) $statement;
37
    }
38
39 2
    private function wrapWithParenthesis(string $value): string
40
    {
41 2
        return sprintf('(%s)', $value);
42
    }
43
44 10
    public function isEmpty(): bool
45
    {
46 10
        return empty($this->statement);
47
    }
48
}
49