Passed
Push — master ( c94b6d...d25cd5 )
by Nikolaos
02:58
created

Delete   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 65.63%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 68
ccs 21
cts 32
cp 0.6563
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 5 1
A __construct() 0 6 1
A reset() 0 6 1
A returning() 0 8 1
A getStatement() 0 7 1
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * (c) Phalcon Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 *
11
 * Implementation of this file has been influenced by AtlasPHP
12
 *
13
 * @link    https://github.com/atlasphp/Atlas.Query
14
 * @license https://github.com/atlasphp/Atlas.Query/blob/1.x/LICENSE.md
15
 */
16
17
declare(strict_types=1);
18
19
namespace Phalcon\DataMapper\Query;
20
21
use Phalcon\DataMapper\Pdo\Connection;
22
23
class Delete extends AbstractConditions
24
{
25
    /**
26
     * Delete constructor.
27
     *
28
     * @param Connection $connection
29
     * @param Bind       $bind
30
     */
31 3
    public function __construct(Connection $connection, Bind $bind)
32
    {
33 3
        parent::__construct($connection, $bind);
34
35 3
        $this->store["FROM"]      = "";
36 3
        $this->store["RETURNING"] = [];
37 3
    }
38
39
    /**
40
     * Adds table(s) in the query
41
     *
42
     * @param string $table
43
     *
44
     * @return Delete
45
     */
46 1
    public function from(string $table): Delete
47
    {
48 1
        $this->store["FROM"] = $table;
49
50 1
        return $this;
51
    }
52
53
    /**
54
     * Adds the `RETURNING` clause
55
     *
56
     * @param array $columns
57
     *
58
     * @return Delete
59
     */
60 1
    public function returning(array $columns): Delete
61
    {
62 1
        $this->store["RETURNING"] = array_merge(
63 1
            $this->store["RETURNING"],
64
            $columns
65
        );
66
67 1
        return $this;
68
    }
69
70
    /**
71
     * @return string
72
     */
73 1
    public function getStatement(): string
74
    {
75
        return "DELETE"
76 1
            . $this->buildFlags()
77 1
            . " FROM " . $this->store["FROM"]
78 1
            . $this->buildCondition("WHERE")
79 1
            . $this->buildReturning();
80
    }
81
82
    /**
83
     * Resets the internal store
84
     */
85 3
    public function reset(): void
86
    {
87 3
        parent::reset();
88
89 3
        $this->store["FROM"]      = "";
90 3
        $this->store["RETURNING"] = [];
91 3
    }
92
}
93