Passed
Push — master ( f181bd...85b9c9 )
by RN
01:43
created

UpdateQueryBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 0 29 3
1
<?php
2
/**
3
 * The Update Query builder Class.
4
 *
5
 * @author RN Kushwaha <[email protected]>
6
 * @since v0.0.8 <Date: 09th May, 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 Insert Queries.
16
 */
17
class UpdateQueryBuilder extends QueryBuilder
18
{
19
    /**
20
     * It inserts the new rows
21
     *
22
     * @param array $rows
23
     * @return integer $lastInsertedId
24
     * @throws Exception
25
     * @author RN Kushwaha <[email protected]>
26
     * @since v0.0.5
27
     */
28
    public function update($rows, $table)
0 ignored issues
show
Unused Code introduced by
The parameter $rows is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
    public function update(/** @scrutinizer ignore-unused */ $rows, $table)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        $db = Connection::get();
0 ignored issues
show
Unused Code introduced by
The assignment to $db is dead and can be removed.
Loading history...
31
        $wqb   = new WhereQueryBuilder();
32
        $query = "UPDATE ".$table." SET ";
33
        $ar    = array();
34
35
        foreach($row as $key => $val){
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $row does not exist. Did you maybe mean $rows?
Loading history...
36
            $ar[':'.$key] = $val;
37
            $query.= $this->quote($key)." =:".$key.",";
38
        }
39
40
        $query = rtrim($query, ",");
41
42
        try{
43
            $whereQuery = $wqb->buildAllWhereQuery(
44
                                $this->where,
0 ignored issues
show
Bug introduced by
The property where does not exist on Dolphin\Builders\UpdateQueryBuilder. Did you mean whereAdded?
Loading history...
45
                                $this->whereRaw,
0 ignored issues
show
Bug Best Practice introduced by
The property whereRaw does not exist on Dolphin\Builders\UpdateQueryBuilder. Did you maybe forget to declare it?
Loading history...
46
                                $this->whereIn,
0 ignored issues
show
Bug Best Practice introduced by
The property whereIn does not exist on Dolphin\Builders\UpdateQueryBuilder. Did you maybe forget to declare it?
Loading history...
47
                                $this->whereNotIn,
0 ignored issues
show
Bug Best Practice introduced by
The property whereNotIn does not exist on Dolphin\Builders\UpdateQueryBuilder. Did you maybe forget to declare it?
Loading history...
48
                                $this->whereNull,
0 ignored issues
show
Bug Best Practice introduced by
The property whereNull does not exist on Dolphin\Builders\UpdateQueryBuilder. Did you maybe forget to declare it?
Loading history...
49
                                $this->whereNotNull
0 ignored issues
show
Bug Best Practice introduced by
The property whereNotNull does not exist on Dolphin\Builders\UpdateQueryBuilder. Did you maybe forget to declare it?
Loading history...
50
                            );
51
            $query.= " ".join(" ", $whereQuery);
52
            $stmt = Connection::get()->prepare($this->queryPrefix($query));
53
            $stmt->execute($ar);
54
            $this->reset();
0 ignored issues
show
Bug introduced by
The method reset() does not exist on Dolphin\Builders\UpdateQueryBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
            $this->/** @scrutinizer ignore-call */ 
55
                   reset();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        } catch(Exception $e){
56
            throw new Exception($e->getMessage());
57
        }
58
    }
59
}
60