DeleteQuery   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 17.95 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 10
dl 7
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A build() 0 13 1
A __clone() 0 7 1

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
/**
4
 * @author Jared King <[email protected]>
5
 *
6
 * @link http://jaredtking.com
7
 *
8
 * @copyright 2015 Jared King
9
 * @license MIT
10
 */
11
namespace JAQB\Query;
12
13
use JAQB\Operations\Executable;
14
use JAQB\Statement\FromStatement;
15
use JAQB\Statement\LimitStatement;
16
use JAQB\Statement\OrderStatement;
17
use JAQB\Statement\WhereStatement;
18
use JAQB\Query\Traits\From;
19
use JAQB\Query\Traits\Limit;
20
use JAQB\Query\Traits\OrderBy;
21
use JAQB\Query\Traits\Where;
22
23
class DeleteQuery extends AbstractQuery
24
{
25
    use Executable, From, Limit, OrderBy, Where;
26
27 View Code Duplication
    public function __construct()
28
    {
29
        $this->from = new FromStatement(FromStatement::DELETE);
30
        $this->where = new WhereStatement();
31
        $this->orderBy = new OrderStatement();
32
        $this->limit = new LimitStatement();
33
    }
34
35
    /**
36
     * Generates the raw SQL string for the query.
37
     *
38
     * @return string
39
     */
40
    public function build()
41
    {
42
        $sql = [
43
            $this->from->build(),
44
            $this->where->build(),
45
            $this->orderBy->build(),
46
            $this->limit->build(),
47
        ];
48
49
        $this->values = $this->where->getValues();
50
51
        return implode(' ', array_filter($sql));
52
    }
53
54
    public function __clone()
55
    {
56
        $this->from = clone $this->from;
57
        $this->where = clone $this->where;
58
        $this->orderBy = clone $this->orderBy;
59
        $this->limit = clone $this->limit;
60
    }
61
}
62