DeleteQueryBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A delete() 0 29 2
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