Delete   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 24.07 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%
Metric Value
dl 13
loc 54
wmc 6
lcom 1
cbo 8
ccs 25
cts 25
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A toString() 13 13 1
A from() 0 6 1
A buildFrom() 0 9 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
namespace Muffin\Queries;
4
5
use Muffin\Query;
6
use Muffin\Condition;
7
use Muffin\Traits\EscaperAware;
8
use Muffin\Snippet;
9
use Muffin\Queries\Snippets\Builders;
10
11
class Delete implements Query
12
{
13
    use
14
        EscaperAware,
15
        Builders\Join,
16
        Builders\Where,
17
        Builders\OrderBy,
18
        Builders\Limit;
19
20
    private
21
        $from;
22
23 7
    public function __construct($table = null, $alias = null)
24
    {
25 7
        if(!empty($table))
26 7
        {
27 2
            $this->from($table, $alias);
28 2
        }
29
30 7
        $this->where = new Snippets\Where();
31 7
        $this->orderBy = new Snippets\OrderBy();
32 7
    }
33
34 7 View Code Duplication
    public function toString()
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...
35
    {
36
        $queryParts = array(
37 7
            'DELETE',
38 7
            $this->buildFrom(),
39 6
            $this->buildJoin(),
40 6
            $this->buildWhere($this->escaper),
41 6
            $this->buildOrderBy(),
42 6
            $this->buildLimit(),
43 6
        );
44
45 6
        return implode(' ', array_filter($queryParts));
46
    }
47
48 6
    public function from($table, $alias = null)
49
    {
50 6
        $this->from = new Snippets\From($table, $alias);
51
52 6
        return $this;
53
    }
54
55 7
    private function buildFrom()
56
    {
57 7
        if(!$this->from instanceof Snippet)
58 7
        {
59 1
            throw new \LogicException('No column for FROM clause');
60
        }
61
62 6
        return $this->from->toString();
63
    }
64
}
65