Conditions | 3 |
Paths | 10 |
Total Lines | 39 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
28 | public function update( |
||
29 | $row, |
||
30 | $table, |
||
31 | $where, |
||
32 | $whereRaw, |
||
33 | $whereIn, |
||
34 | $whereNotIn, |
||
35 | $whereNull, |
||
36 | $whereNotNull |
||
37 | ): bool |
||
38 | { |
||
39 | $wqb = new WhereQueryBuilder(); |
||
40 | $query = "UPDATE ".$table." SET "; |
||
41 | $ar = []; |
||
42 | |||
43 | foreach($row as $key => $val){ |
||
44 | $ar[':'.$key] = $val; |
||
45 | $query.= $this->quote($key)." =:".$key.","; |
||
46 | } |
||
47 | |||
48 | $query = rtrim($query, ","); |
||
49 | |||
50 | try{ |
||
51 | $whereQuery = $wqb->buildAllWhereQuery( |
||
52 | $where, |
||
53 | $whereRaw, |
||
54 | $whereIn, |
||
55 | $whereNotIn, |
||
56 | $whereNull, |
||
57 | $whereNotNull |
||
58 | ); |
||
59 | $query.= " ".join(" ", $whereQuery); |
||
60 | $stmt = Connection::get()->prepare($this->queryPrefix($query)); |
||
61 | $stmt->execute($ar); |
||
62 | } catch(Exception $e){ |
||
63 | throw new Exception($e->getMessage()); |
||
64 | } |
||
65 | |||
66 | return true; |
||
67 | } |
||
69 |