Between::isEmpty()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.2
cc 4
eloc 5
nc 2
nop 0
crap 4
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Conditions;
6
7
use Puzzle\QueryBuilder\Conditions\AbstractCondition;
8
use Puzzle\QueryBuilder\Escaper;
9
use Puzzle\QueryBuilder\Type;
10
11
class Between extends AbstractCondition
12
{
13
    protected
14
        $column,
1 ignored issue
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $column.

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...
15
        $start,
16
        $end;
17
18 14
    public function __construct(Type $column, $start, $end)
19
    {
20 14
        $this->column = $column;
21 14
        $this->start = $start;
22 14
        $this->end = $end;
23 14
    }
24
25 7
    public function toString(Escaper $escaper): string
26
    {
27 7
        if($this->isEmpty())
28
        {
29 2
            return '';
30
        }
31
32 5
        return sprintf(
33 5
            '%s BETWEEN %s AND %s',
34 5
            $this->column->getName(),
35 5
            $this->escapeValue($this->start, $escaper),
36 5
            $this->escapeValue($this->end, $escaper)
37
        );
38
    }
39
40 15
    public function isEmpty(): bool
41
    {
42 15
        $columnName = $this->column->getName();
43
44 15
        if(empty($columnName) || empty($this->start) || empty($this->end))
45
        {
46 8
            return true;
47
        }
48
49 7
        return false;
50
    }
51
52 5 View Code Duplication
    private function escapeValue($value, Escaper $escaper)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54 5
        $value = $this->column->format($value);
55
56 5
        if($this->column->isEscapeRequired())
57
        {
58 4
            $value = $escaper->escape($value);
59
        }
60
61 5
        return $value;
62
    }
63
}
64