Delete::from()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4286
cc 1
eloc 3
nc 1
nop 2
crap 1
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