DeleteQueryBuilder::delete()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 15
nc 4
nop 7
dl 0
loc 29
rs 9.7666
c 1
b 0
f 0
1
<?php
2
/**
3
 * The Delete Query builder Class.
4
 *
5
 * @author RN Kushwaha <[email protected]>
6
 * @since v0.0.8 <Date: 29th Dec, 2019>
7
 */
8
9
namespace Dolphin\Builders;
10
11
use Dolphin\Connections\Connection;
12
use Exception;
13
14
/**
15
 * This class provides the mechanism to build the Delete Queries.
16
 */
17
class DeleteQueryBuilder extends QueryBuilder
18
{
19
    /**
20
     * It deletes the matching rows
21
     *
22
     * @param array $rows
23
     * @return boolean
24
     * @throws Exception
25
     * @author RN Kushwaha <[email protected]>
26
     * @since v0.0.8
27
     */
28
    public function delete(
29
      $table,
30
      $where,
31
      $whereRaw,
32
      $whereIn,
33
      $whereNotIn,
34
      $whereNull,
35
      $whereNotNull
36
    ): bool
37
    {
38
        $wqb = new WhereQueryBuilder();
39
        $query = "DELETE FROM ".$table;
40
41
        try{
42
            $whereQuery = $wqb->buildAllWhereQuery(
43
                                    $where,
44
                                    $whereRaw,
45
                                    $whereIn,
46
                                    $whereNotIn,
47
                                    $whereNull,
48
                                    $whereNotNull
49
                                );
50
            $query.= " ".join(" ", $whereQuery);
51
            Connection::get()->query($this->queryPrefix($query));
52
        } catch(Exception $e){
53
            throw new Exception($e->getMessage());
54
        }
55
56
        return true;
57
    }
58
}
59