Between   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 20.75 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 11
loc 53
c 0
b 0
f 0
wmc 9
lcom 1
cbo 3
ccs 23
cts 23
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A toString() 0 14 2
A isEmpty() 0 11 4
A escapeValue() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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