@@ -15,7 +15,7 @@ |
||
| 15 | 15 | $dbCredentials = require('database.php'); |
| 16 | 16 | $var = $arguments[0]; |
| 17 | 17 | |
| 18 | - if(array_key_exists($var, $dbCredentials)){ |
|
| 18 | + if (array_key_exists($var, $dbCredentials)) { |
|
| 19 | 19 | return $dbCredentials[$var]; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | |
| 27 | 27 | public function __call($method, $parameters) |
| 28 | 28 | { |
| 29 | - if($method== 'asArray'){ |
|
| 29 | + if ($method == 'asArray') { |
|
| 30 | 30 | // $obj = new Utils(); |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | class WhereQueryParser |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - protected function prepareArrayForWhere($bindKey, $bindVal = null){ |
|
| 16 | + protected function prepareArrayForWhere($bindKey, $bindVal = null) { |
|
| 17 | 17 | $ar = $conditionAr = array(); |
| 18 | 18 | // expecting a string like 'status = :status' |
| 19 | 19 | if ($this->checkWherePrepareUsed($bindKey)) { |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function turnObject($destination, $sourceObject) |
| 29 | 29 | { |
| 30 | 30 | $destination = new $destination(); |
| 31 | - if(!is_object($sourceObject)){ |
|
| 31 | + if (!is_object($sourceObject)) { |
|
| 32 | 32 | return $destination; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | if ($destinationReflection->hasProperty($name)) { |
| 45 | 45 | $propDest = $destinationReflection->getProperty($name); |
| 46 | 46 | $propDest->setAccessible(true); |
| 47 | - $propDest->setValue($destination,$value); |
|
| 47 | + $propDest->setValue($destination, $value); |
|
| 48 | 48 | } else { |
| 49 | 49 | $destination->$name = $value; |
| 50 | 50 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public function turnObjects($destination, $data) |
| 67 | 67 | { |
| 68 | 68 | $destination = new $destination(); |
| 69 | - if(count($data)){ |
|
| 69 | + if (count($data)) { |
|
| 70 | 70 | $destination->data = json_decode(json_encode($data, true)); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -22,33 +22,33 @@ discard block |
||
| 22 | 22 | $this->qb = new QueryBuilder(); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function buildQueryStrSingleFromArr($row = array()){ |
|
| 25 | + public function buildQueryStrSingleFromArr($row = array()) { |
|
| 26 | 26 | $ar = []; |
| 27 | 27 | $query = "UPDATE ".$this->table." SET "; |
| 28 | - foreach($row as $key => $val){ |
|
| 28 | + foreach ($row as $key => $val) { |
|
| 29 | 29 | $ar[':'.$key] = $val; |
| 30 | - if($key == 'id') continue; |
|
| 31 | - $query.= $this->qb->quote($key)." =:".$key.","; |
|
| 30 | + if ($key == 'id') continue; |
|
| 31 | + $query .= $this->qb->quote($key)." =:".$key.","; |
|
| 32 | 32 | } |
| 33 | 33 | $query = rtrim($query, ","); |
| 34 | 34 | |
| 35 | 35 | return ['ar' => $ar, 'query' => $query]; |
| 36 | 36 | } |
| 37 | - public function createQuery($row){ |
|
| 37 | + public function createQuery($row) { |
|
| 38 | 38 | $ar = []; |
| 39 | - if(isset($row) && isset($row->id) && $row->id > 0 ){ |
|
| 39 | + if (isset($row) && isset($row->id) && $row->id > 0) { |
|
| 40 | 40 | $mixedData = $this->buildQueryStrSingleFromArr($row); |
| 41 | - $query= $mixedData['query']." WHERE ".$this->qb->quote('id')."=:id"; |
|
| 41 | + $query = $mixedData['query']." WHERE ".$this->qb->quote('id')."=:id"; |
|
| 42 | 42 | |
| 43 | 43 | return ['query' => $query, 'data' => $mixedData['ar']]; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $queryVal = ''; |
| 47 | 47 | $query = "INSERT INTO ".$this->table." ("; |
| 48 | - foreach($row as $key => $val){ |
|
| 49 | - $query.= $this->qb->quote($key).", "; |
|
| 48 | + foreach ($row as $key => $val) { |
|
| 49 | + $query .= $this->qb->quote($key).", "; |
|
| 50 | 50 | $ar[$key] = $val; |
| 51 | - $queryVal.= ":".$key.", "; |
|
| 51 | + $queryVal .= ":".$key.", "; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $query = rtrim($query, ", ").") VALUES (".$queryVal.rtrim($query, ", ").") "; |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | list($query, $data) = $this->createQuery($row); |
| 75 | 75 | |
| 76 | - try{ |
|
| 76 | + try { |
|
| 77 | 77 | $stmt = Connection::get()->prepare($this->qb->queryPrefix($query)); |
| 78 | 78 | $stmt->execute($data); |
| 79 | - } catch(Exception $e){ |
|
| 79 | + } catch (Exception $e) { |
|
| 80 | 80 | throw new Exception($e->getMessage()); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | return "'".$field."'"; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - private function getQueryFields($fields, $tbl){ |
|
| 71 | + private function getQueryFields($fields, $tbl) { |
|
| 72 | 72 | $startQuery = join(', ', $fields); |
| 73 | 73 | if (empty($fields)) { |
| 74 | 74 | $startQuery = $this->quote($tbl).'.*'; |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | return $startQuery; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - private function buildLimitQuery($limit, $offset, $query = array()){ |
|
| 80 | + private function buildLimitQuery($limit, $offset, $query = array()) { |
|
| 81 | 81 | $limitQuery = []; |
| 82 | 82 | if (!empty($limit)) { |
| 83 | 83 | $query[] = 'LIMIT'; |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | private $qb; |
| 19 | 19 | |
| 20 | - public function __construct(){ |
|
| 20 | + public function __construct() { |
|
| 21 | 21 | $this->qb = new QueryBuilder(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - private function emptyConditionsResponse($conditions = array()){ |
|
| 24 | + private function emptyConditionsResponse($conditions = array()) { |
|
| 25 | 25 | if (!count($conditions)) { |
| 26 | 26 | return array(); |
| 27 | 27 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | foreach ($conditions as $where) { |
| 54 | 54 | $sign = '='; |
| 55 | - if(count($where)==3) { |
|
| 55 | + if (count($where) == 3) { |
|
| 56 | 56 | $sign = $where[1]; |
| 57 | 57 | } |
| 58 | 58 | if ($firstTime) { |
@@ -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 | } |