Delete   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 60
c 0
b 0
f 0
wmc 6
lcom 1
cbo 8
ccs 21
cts 21
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A toString() 0 13 1
A from() 0 6 1
A buildFrom() 0 9 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Queries;
6
7
use Puzzle\QueryBuilder\Query;
8
use Puzzle\QueryBuilder\Traits\EscaperAware;
9
use Puzzle\QueryBuilder\Snippet;
10
use Puzzle\QueryBuilder\Queries\Snippets\Builders;
11
12
class Delete implements Query
13
{
14
    use
15
        EscaperAware,
16
        Builders\Join,
17
        Builders\Where,
18
        Builders\OrderBy,
19
        Builders\Limit;
20
21
    private
22
        $from;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $from.

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...
23
24
    /**
25
     * @param TableName|string $table
26
     */
27 7
    public function __construct($table = null, ?string $alias = null)
28
    {
29 7
        if(!empty($table))
30
        {
31 2
            $this->from($table, $alias);
32
        }
33
34 7
        $this->where = new Snippets\Where();
35 7
        $this->orderBy = new Snippets\OrderBy();
36 7
    }
37
38 7
    public function toString(): string
39
    {
40
        $queryParts = array(
41 7
            'DELETE',
42 7
            $this->buildFrom(),
43 6
            $this->buildJoin(),
44 6
            $this->buildWhere($this->escaper),
45 6
            $this->buildOrderBy(),
46 6
            $this->buildLimit(),
47
        );
48
49 6
        return implode(' ', array_filter($queryParts));
50
    }
51
52
    /**
53
     * @param TableName|string $table
54
     */
55 6
    public function from($table, ?string $alias = null): self
56
    {
57 6
        $this->from = new Snippets\From($table, $alias);
58
59 6
        return $this;
60
    }
61
62 7
    private function buildFrom(): string
63
    {
64 7
        if(!$this->from instanceof Snippet)
65
        {
66 1
            throw new \LogicException('No column for FROM clause');
67
        }
68
69 6
        return $this->from->toString();
70
    }
71
}
72