Completed
Pull Request — master (#11)
by Romain
03:32
created

Delete   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 28.81 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 96.43%

Importance

Changes 0
Metric Value
dl 17
loc 59
c 0
b 0
f 0
wmc 6
lcom 1
cbo 9
ccs 27
cts 28
cp 0.9643
rs 10

4 Methods

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