Between::isEmpty()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.2
cc 4
eloc 5
nc 2
nop 0
crap 4
1
<?php
2
3
namespace Muffin\Conditions;
4
5
use Muffin\Conditions\AbstractCondition;
6
use Muffin\Escaper;
7
8
class Between extends AbstractCondition
9
{
10
    protected
11
        $type,
12
        $start,
13
        $end;
14
15 15
    public function __construct($column, $start, $end)
16
    {
17 15
        $this->type = $column;
18 15
        $this->start = $start;
19 15
        $this->end = $end;
20 15
    }
21
22 7
    public function toString(Escaper $escaper)
23
    {
24 7
        if($this->isEmpty())
25 7
        {
26 2
            return '';
27
        }
28
29 5
        return sprintf(
30 5
            '%s BETWEEN %s AND %s',
31 5
            $this->type->getName(),
32 5
            $this->escapeValue($this->start, $escaper),
33 5
            $this->escapeValue($this->end, $escaper)
34 5
        );
35
    }
36
37 15
    public function isEmpty()
38
    {
39 15
        $columnName = $this->type->getName();
40 15
        if(empty($columnName) || empty($this->start) || empty($this->end))
41 15
        {
42 8
            return true;
43
        }
44
45 7
        return false;
46
    }
47
48 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...
49
    {
50 5
        $value = $this->type->format($value);
51
52 5
        if($this->type->isEscapeRequired())
53 5
        {
54 4
            $value = $escaper->escape($value);
55 4
        }
56
57 5
        return $value;
58
    }
59
}
60