@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @return $this |
| 16 | 16 | */ |
| 17 | 17 | protected function addTable($alias, $table = null) { |
| 18 | - if($table === null) { |
|
| 18 | + if ($table === null) { |
|
| 19 | 19 | list($alias, $table) = [$table, $alias]; |
| 20 | 20 | } |
| 21 | 21 | $this->tables[] = ['alias' => $alias, 'name' => $table]; |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | protected function buildTables(string $query): string { |
| 30 | 30 | $arr = []; |
| 31 | - foreach($this->tables as $table) { |
|
| 31 | + foreach ($this->tables as $table) { |
|
| 32 | 32 | $arr[] = "\t".$this->buildTableName($table['alias'], $table['name']); |
| 33 | 33 | } |
| 34 | - if(count($arr)) { |
|
| 34 | + if (count($arr)) { |
|
| 35 | 35 | $query .= implode(",\n", $arr)."\n"; |
| 36 | 36 | } |
| 37 | 37 | return $query; |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | * @return $this |
| 13 | 13 | */ |
| 14 | 14 | public function groupBy(...$args) { |
| 15 | - foreach($args as $expression) { |
|
| 16 | - if(is_array($expression)) { |
|
| 17 | - if(!count($expression)) { |
|
| 15 | + foreach ($args as $expression) { |
|
| 16 | + if (is_array($expression)) { |
|
| 17 | + if (!count($expression)) { |
|
| 18 | 18 | continue; |
| 19 | 19 | } |
| 20 | 20 | $arguments = [ |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | 35 | protected function buildGroups(string $query): string { |
| 36 | - if(!count($this->groupBy)) { |
|
| 36 | + if (!count($this->groupBy)) { |
|
| 37 | 37 | return $query; |
| 38 | 38 | } |
| 39 | 39 | $query .= "GROUP BY\n"; |
| 40 | 40 | $arr = []; |
| 41 | - foreach($this->groupBy as $expression) { |
|
| 41 | + foreach ($this->groupBy as $expression) { |
|
| 42 | 42 | $arr[] = "\t{$expression}"; |
| 43 | 43 | } |
| 44 | 44 | return $query.implode(",\n", $arr)."\n"; |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | 28 | protected function buildOffset(string $query): string { |
| 29 | - if($this->offset !== null) { |
|
| 29 | + if ($this->offset !== null) { |
|
| 30 | 30 | $query .= "OFFSET\n\t{$this->offset}\n"; |
| 31 | 31 | } |
| 32 | 32 | return $query; |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * @return $this |
| 15 | 15 | */ |
| 16 | 16 | public function union(...$queries) { |
| 17 | - foreach($queries as $query) { |
|
| 17 | + foreach ($queries as $query) { |
|
| 18 | 18 | $this->unions[] = ['', $query]; |
| 19 | 19 | } |
| 20 | 20 | return $this; |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @return $this |
| 26 | 26 | */ |
| 27 | 27 | public function unionAll(...$queries) { |
| 28 | - foreach($queries as $query) { |
|
| 28 | + foreach ($queries as $query) { |
|
| 29 | 29 | $this->unions[] = ['ALL', $query]; |
| 30 | 30 | } |
| 31 | 31 | return $this; |
@@ -36,21 +36,21 @@ discard block |
||
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | 38 | protected function buildUnions(string $query): string { |
| 39 | - $wrap = static function ($query) { |
|
| 39 | + $wrap = static function($query) { |
|
| 40 | 40 | $query = trim($query); |
| 41 | 41 | $query = implode("\n\t", explode("\n", $query)); |
| 42 | 42 | return sprintf("(\n\t%s\n)", $query); |
| 43 | 43 | }; |
| 44 | 44 | $queries = [$wrap($query)]; |
| 45 | - foreach($this->unions as $unionQuery) { |
|
| 46 | - if($unionQuery[0] === 'ALL') { |
|
| 45 | + foreach ($this->unions as $unionQuery) { |
|
| 46 | + if ($unionQuery[0] === 'ALL') { |
|
| 47 | 47 | $queries[] = 'UNION ALL'; |
| 48 | 48 | } else { |
| 49 | 49 | $queries[] = 'UNION'; |
| 50 | 50 | } |
| 51 | 51 | $queries[] = $wrap($unionQuery[1]); |
| 52 | 52 | } |
| 53 | - if(count($queries) > 1) { |
|
| 53 | + if (count($queries) > 1) { |
|
| 54 | 54 | return implode(' ', $queries); |
| 55 | 55 | } |
| 56 | 56 | return $query; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return $this |
| 30 | 30 | */ |
| 31 | 31 | public function from(string $alias, $table = null) { |
| 32 | - if($table !== null) { |
|
| 32 | + if ($table !== null) { |
|
| 33 | 33 | $this->aliases[] = $alias; |
| 34 | 34 | } |
| 35 | 35 | $this->addTable($alias, $table); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | public function __toString(): string { |
| 43 | 43 | $query = "DELETE "; |
| 44 | 44 | $query .= implode(', ', $this->aliases); |
| 45 | - $query = trim($query) . " FROM\n"; |
|
| 45 | + $query = trim($query)." FROM\n"; |
|
| 46 | 46 | $query = $this->buildTables($query); |
| 47 | 47 | $query = $this->buildJoins($query); |
| 48 | 48 | $query = $this->buildWhereConditions($query); |
@@ -47,10 +47,10 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array $arg1 = null) { |
| 49 | 49 | $args = [$mode]; |
| 50 | - if($arg0 !== null) { |
|
| 50 | + if ($arg0 !== null) { |
|
| 51 | 51 | $args[] = $arg0; |
| 52 | 52 | } |
| 53 | - if($arg1 !== null) { |
|
| 53 | + if ($arg1 !== null) { |
|
| 54 | 54 | $args[] = $arg1; |
| 55 | 55 | } |
| 56 | 56 | $this->statement->setFetchMode(...$args); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $timer = microtime(true); |
| 68 | 68 | $response = $this->statement->execute($params); |
| 69 | 69 | $this->queryLoggers->log($this->query, microtime(true)-$timer); |
| 70 | - if(!$response) { |
|
| 70 | + if (!$response) { |
|
| 71 | 71 | throw new SqlException('Execution returned with "false".'); |
| 72 | 72 | } |
| 73 | 73 | }); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function fetchAll($fetchStyle = null, $fetchArgument = null, array $ctorArgs = []): array { |
| 84 | 84 | return $this->exceptionHandler(function() use ($fetchStyle, $fetchArgument, $ctorArgs) { |
| 85 | - if($fetchArgument !== null) { |
|
| 85 | + if ($fetchArgument !== null) { |
|
| 86 | 86 | return $this->statement->fetchAll($fetchStyle, $fetchArgument, $ctorArgs); |
| 87 | 87 | } |
| 88 | 88 | return $this->statement->fetchAll($fetchStyle); |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | * @return $this |
| 62 | 62 | */ |
| 63 | 63 | public function setExpr(string $expr, ...$args) { |
| 64 | - if(count($args) > 0) { |
|
| 64 | + if (count($args) > 0) { |
|
| 65 | 65 | $this->fields[] = func_get_args(); |
| 66 | 66 | } else { |
| 67 | 67 | $this->fields[] = $expr; |