@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | protected $offset; |
| 74 | 74 | protected $results; |
| 75 | 75 | |
| 76 | - private function getFields(array $args, bool $quote = true){ |
|
| 76 | + private function getFields(array $args, bool $quote = true) { |
|
| 77 | 77 | $fldAr = array(); |
| 78 | 78 | $qb = new QueryBuilder(); |
| 79 | 79 | |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | return $fldAr; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - private function validateArgsCount($noOfArgs){ |
|
| 90 | - if($noOfArgs<2 || $noOfArgs >3){ |
|
| 89 | + private function validateArgsCount($noOfArgs) { |
|
| 90 | + if ($noOfArgs < 2 || $noOfArgs > 3) { |
|
| 91 | 91 | throw new Exception('Where parameter contains invalid number of parameters', 1); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | $this->validateArgsCount($noOfArgs); |
| 150 | 150 | |
| 151 | - if($noOfArgs===2){ |
|
| 151 | + if ($noOfArgs === 2) { |
|
| 152 | 152 | $this->where = array_merge($this->where, [[$args[0], '=', $args[1]]]); |
| 153 | 153 | return $this; |
| 154 | 154 | } |
@@ -294,11 +294,11 @@ discard block |
||
| 294 | 294 | |
| 295 | 295 | if ($fetchRows == 'first') { |
| 296 | 296 | $this->results = $stmt->fetch(\PDO::FETCH_OBJ); |
| 297 | - } else{ |
|
| 297 | + } else { |
|
| 298 | 298 | $this->results = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if(count($this->results) ){ |
|
| 301 | + if (count($this->results)) { |
|
| 302 | 302 | // now turn this stdClass object to the object type of calling model |
| 303 | 303 | $rows = $util->turnObjects($this->className, $this->results); |
| 304 | 304 | } |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | |
| 385 | 385 | $row = $this->first(); |
| 386 | 386 | |
| 387 | - if($row == null ){ |
|
| 387 | + if ($row == null) { |
|
| 388 | 388 | throw new Exception("The record does not exists!"); |
| 389 | 389 | } |
| 390 | 390 | |
@@ -412,9 +412,9 @@ discard block |
||
| 412 | 412 | $qb = new QueryBuilder(); |
| 413 | 413 | $query = "TRUNCATE ".$this->table; |
| 414 | 414 | |
| 415 | - try{ |
|
| 415 | + try { |
|
| 416 | 416 | Connection::get()->query($qb->queryPrefix($query)); |
| 417 | - } catch(Exception $e){ |
|
| 417 | + } catch (Exception $e) { |
|
| 418 | 418 | throw new Exception($e->getMessage()); |
| 419 | 419 | } |
| 420 | 420 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | $wqb = new WhereQueryBuilder(); |
| 463 | 463 | $query = "DELETE FROM ".$this->table; |
| 464 | 464 | |
| 465 | - try{ |
|
| 465 | + try { |
|
| 466 | 466 | $whereQuery = $wqb->buildAllWhereQuery( |
| 467 | 467 | $this->where, |
| 468 | 468 | $this->whereRaw, |
@@ -471,10 +471,10 @@ discard block |
||
| 471 | 471 | $this->whereNull, |
| 472 | 472 | $this->whereNotNull |
| 473 | 473 | ); |
| 474 | - $query.= " ".join(" ", $whereQuery); |
|
| 474 | + $query .= " ".join(" ", $whereQuery); |
|
| 475 | 475 | Connection::get()->query($qb->queryPrefix($query)); |
| 476 | 476 | $this->reset(); |
| 477 | - } catch(Exception $e){ |
|
| 477 | + } catch (Exception $e) { |
|
| 478 | 478 | throw new Exception($e->getMessage()); |
| 479 | 479 | } |
| 480 | 480 | |
@@ -32,14 +32,14 @@ discard block |
||
| 32 | 32 | $query = "UPDATE ".$table." SET "; |
| 33 | 33 | $ar = array(); |
| 34 | 34 | |
| 35 | - foreach($row as $key => $val){ |
|
| 35 | + foreach ($row as $key => $val) { |
|
| 36 | 36 | $ar[':'.$key] = $val; |
| 37 | - $query.= $this->quote($key)." =:".$key.","; |
|
| 37 | + $query .= $this->quote($key)." =:".$key.","; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $query = rtrim($query, ","); |
| 41 | 41 | |
| 42 | - try{ |
|
| 42 | + try { |
|
| 43 | 43 | $whereQuery = $wqb->buildAllWhereQuery( |
| 44 | 44 | $this->where, |
| 45 | 45 | $this->whereRaw, |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | $this->whereNull, |
| 49 | 49 | $this->whereNotNull |
| 50 | 50 | ); |
| 51 | - $query.= " ".join(" ", $whereQuery); |
|
| 51 | + $query .= " ".join(" ", $whereQuery); |
|
| 52 | 52 | $stmt = Connection::get()->prepare($this->queryPrefix($query)); |
| 53 | 53 | $stmt->execute($ar); |
| 54 | 54 | $this->reset(); |
| 55 | - } catch(Exception $e){ |
|
| 55 | + } catch (Exception $e) { |
|
| 56 | 56 | throw new Exception($e->getMessage()); |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -16,55 +16,55 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class InsertQueryBuilder extends QueryBuilder |
| 18 | 18 | { |
| 19 | - private function buildInsert($table, $obj){ |
|
| 19 | + private function buildInsert($table, $obj) { |
|
| 20 | 20 | $qb = new QueryBuilder(); |
| 21 | 21 | $query = "INSERT INTO ".$table." ("; |
| 22 | - foreach($obj as $key => $val){ |
|
| 23 | - $query.= $qb->quote($key).", "; |
|
| 22 | + foreach ($obj as $key => $val) { |
|
| 23 | + $query .= $qb->quote($key).", "; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | $query = rtrim($query, ", "); |
| 27 | - $query.= ") VALUES "; |
|
| 27 | + $query .= ") VALUES "; |
|
| 28 | 28 | |
| 29 | 29 | return $query; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - private function buildInsertPlaceholder($rows){ |
|
| 32 | + private function buildInsertPlaceholder($rows) { |
|
| 33 | 33 | $ar = array(); |
| 34 | 34 | $query = "("; |
| 35 | 35 | |
| 36 | - foreach($rows as $key => $val){ |
|
| 36 | + foreach ($rows as $key => $val) { |
|
| 37 | 37 | $ar[$key] = $val; |
| 38 | - $query.= ":".$key.", "; |
|
| 38 | + $query .= ":".$key.", "; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $query = rtrim($query, ", "); |
| 42 | - $query.=") "; |
|
| 42 | + $query .= ") "; |
|
| 43 | 43 | |
| 44 | 44 | return ['query' => $query, 'array' => $ar]; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - private function buildInsertPlaceholders($rows){ |
|
| 47 | + private function buildInsertPlaceholders($rows) { |
|
| 48 | 48 | $bindAr = array(); |
| 49 | 49 | $query = ""; |
| 50 | 50 | |
| 51 | - foreach($rows as $i => $row){ |
|
| 52 | - $query.="("; |
|
| 53 | - foreach($row as $key => $val){ |
|
| 54 | - $param = ":" . $key . $i; |
|
| 55 | - $query.= $param.", "; |
|
| 51 | + foreach ($rows as $i => $row) { |
|
| 52 | + $query .= "("; |
|
| 53 | + foreach ($row as $key => $val) { |
|
| 54 | + $param = ":".$key.$i; |
|
| 55 | + $query .= $param.", "; |
|
| 56 | 56 | $bindAr[$param] = $val; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $query = rtrim($query, ", "); |
| 60 | - $query.="), "; |
|
| 60 | + $query .= "), "; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $query = rtrim($query, ", "); |
| 64 | 64 | return ['query' => $query, 'array' => $bindAr]; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - private function checkMultipleInsert($rows = array()){ |
|
| 67 | + private function checkMultipleInsert($rows = array()) { |
|
| 68 | 68 | return is_array($rows) && isset($rows[0]) && is_array($rows[0]); |
| 69 | 69 | } |
| 70 | 70 | /** |
@@ -83,21 +83,21 @@ discard block |
||
| 83 | 83 | $dataToBuild = $rows; |
| 84 | 84 | $methodToCall = 'buildInsertPlaceholder'; |
| 85 | 85 | |
| 86 | - if($this->checkMultipleInsert($rows)){ |
|
| 86 | + if ($this->checkMultipleInsert($rows)) { |
|
| 87 | 87 | $dataToBuild = $rows[0]; |
| 88 | 88 | $methodToCall = 'buildInsertPlaceholders'; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $query = $this->buildInsert($table, $dataToBuild); |
| 92 | 92 | $dataRet = $this->$methodToCall($rows); |
| 93 | - $query.= $dataRet['query']; |
|
| 93 | + $query .= $dataRet['query']; |
|
| 94 | 94 | $bindAr = $dataRet['array']; |
| 95 | 95 | |
| 96 | - try{ |
|
| 96 | + try { |
|
| 97 | 97 | $stmt = $db->prepare($this->queryPrefix($query)); |
| 98 | 98 | |
| 99 | - if($this->checkMultipleInsert($rows)){ |
|
| 100 | - foreach($bindAr as $param => $val){ |
|
| 99 | + if ($this->checkMultipleInsert($rows)) { |
|
| 100 | + foreach ($bindAr as $param => $val) { |
|
| 101 | 101 | $stmt->bindValue($param, $val); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $stmt->execute($bindAr); |
| 109 | 109 | return $db->lastInsertId(); |
| 110 | - } catch(Exception $e){ |
|
| 110 | + } catch (Exception $e) { |
|
| 111 | 111 | throw new Exception($e->getMessage()); |
| 112 | 112 | } |
| 113 | 113 | } |