@@ -25,7 +25,7 @@ |
||
| 25 | 25 | public function run(array $params = []) { |
| 26 | 26 | $this->query->execute($params); |
| 27 | 27 | $response = $this->query->getStatement()->rowCount(); |
| 28 | - if($this->callbackFn !== null) { |
|
| 28 | + if ($this->callbackFn !== null) { |
|
| 29 | 29 | $response = call_user_func($this->callbackFn, $response); |
| 30 | 30 | } |
| 31 | 31 | return $response; |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | /** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */ |
| 20 | 20 | $code = is_array($errorInfo) && isset($errorInfo[1]) ? ((int) $errorInfo[1]) : ((int) $exception->getCode()); |
| 21 | 21 | $message = $exception->getMessage(); |
| 22 | - switch($code) { |
|
| 22 | + switch ($code) { |
|
| 23 | 23 | case 2006: throw new DatabaseHasGoneAwayException($message, $code, $exception); |
| 24 | 24 | case 1213: throw new SqlDeadLockException($message, $code, $exception); |
| 25 | 25 | case 1205: throw new LockWaitTimeoutExceededException($message, $code, $exception); |
@@ -31,10 +31,10 @@ |
||
| 31 | 31 | * @return Select|null |
| 32 | 32 | */ |
| 33 | 33 | public function get($tableName): ?Select { |
| 34 | - if($this->has($tableName)) { |
|
| 34 | + if ($this->has($tableName)) { |
|
| 35 | 35 | $table = $this->virtualTables[(string) $tableName]; |
| 36 | - if($table instanceof Closure) { |
|
| 37 | - if($tableName instanceof VirtualTable) { |
|
| 36 | + if ($table instanceof Closure) { |
|
| 37 | + if ($tableName instanceof VirtualTable) { |
|
| 38 | 38 | $params = $tableName->getParams(); |
| 39 | 39 | return $table($params); |
| 40 | 40 | } |
@@ -49,15 +49,15 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | protected function buildJoins(string $query): string { |
| 51 | 51 | $arr = []; |
| 52 | - foreach($this->joinTables as $table) { |
|
| 52 | + foreach ($this->joinTables as $table) { |
|
| 53 | 53 | $join = $table['type']." JOIN\n"; |
| 54 | - $join .= "\t" . $this->buildTableName($table['alias'], $table['name']); |
|
| 55 | - if($table['expression']) { |
|
| 56 | - $join .= " ON " . $this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
| 54 | + $join .= "\t".$this->buildTableName($table['alias'], $table['name']); |
|
| 55 | + if ($table['expression']) { |
|
| 56 | + $join .= " ON ".$this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
| 57 | 57 | } |
| 58 | 58 | $arr[] = $join; |
| 59 | 59 | } |
| 60 | - if(count($arr)) { |
|
| 60 | + if (count($arr)) { |
|
| 61 | 61 | $query .= implode("\n", $arr)."\n"; |
| 62 | 62 | } |
| 63 | 63 | 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; |
@@ -14,34 +14,34 @@ |
||
| 14 | 14 | * @return string |
| 15 | 15 | */ |
| 16 | 16 | protected function buildTableName(?string $alias, $name): string { |
| 17 | - if(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
| 17 | + if (is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
|
| 18 | 18 | $name = (string) $name; |
| 19 | 19 | $lines = explode("\n", $name); |
| 20 | - $lines = array_map(static function (string $line) { return "\t{$line}"; }, $lines); |
|
| 20 | + $lines = array_map(static function(string $line) { return "\t{$line}"; }, $lines); |
|
| 21 | 21 | $name = implode("\n", $lines); |
| 22 | - $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
|
| 22 | + $name = '('.trim(rtrim(trim($name), ';')).')'; |
|
| 23 | 23 | } |
| 24 | - if(is_array($name)) { |
|
| 24 | + if (is_array($name)) { |
|
| 25 | 25 | $parts = []; |
| 26 | - foreach($name as $index => $bucket) { |
|
| 27 | - if(is_scalar($bucket) && ctype_digit((string) $index)) { |
|
| 26 | + foreach ($name as $index => $bucket) { |
|
| 27 | + if (is_scalar($bucket) && ctype_digit((string) $index)) { |
|
| 28 | 28 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
| 29 | 29 | } else { |
| 30 | 30 | $values = []; |
| 31 | - foreach($bucket as $field => $value) { |
|
| 31 | + foreach ($bucket as $field => $value) { |
|
| 32 | 32 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
| 33 | 33 | } |
| 34 | 34 | $parts[] = sprintf("SELECT %s", implode(', ', $values)); |
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | - $name = '(' . implode("\n\tUNION\n\t", $parts) . ')'; |
|
| 37 | + $name = '('.implode("\n\tUNION\n\t", $parts).')'; |
|
| 38 | 38 | } |
| 39 | - if((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
| 39 | + if ((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
|
| 40 | 40 | $select = (string) $this->db()->getVirtualTables()->get($name); |
| 41 | 41 | $name = sprintf('(%s)', implode("\n\t", explode("\n", trim($select)))); |
| 42 | 42 | } |
| 43 | 43 | $name = $this->aliasReplacer()->replace((string) $name); |
| 44 | - if($alias !== null) { |
|
| 44 | + if ($alias !== null) { |
|
| 45 | 45 | return sprintf("%s %s", $name, $alias); |
| 46 | 46 | } |
| 47 | 47 | return $name; |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | * @return $this |
| 15 | 15 | */ |
| 16 | 16 | public function groupBy(...$args) { |
| 17 | - foreach($args as $expression) { |
|
| 18 | - if(is_array($expression)) { |
|
| 19 | - if(!count($expression)) { |
|
| 17 | + foreach ($args as $expression) { |
|
| 18 | + if (is_array($expression)) { |
|
| 19 | + if (!count($expression)) { |
|
| 20 | 20 | continue; |
| 21 | 21 | } |
| 22 | 22 | $expression = $this->quoteExpr($expression[0], array_slice($expression, 1)); |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | 33 | protected function buildGroups(string $query): string { |
| 34 | - if(!count($this->groupBy)) { |
|
| 34 | + if (!count($this->groupBy)) { |
|
| 35 | 35 | return $query; |
| 36 | 36 | } |
| 37 | 37 | $query .= "GROUP BY\n"; |
| 38 | 38 | $arr = []; |
| 39 | - foreach($this->groupBy as $expression) { |
|
| 39 | + foreach ($this->groupBy as $expression) { |
|
| 40 | 40 | $arr[] = "\t{$expression}"; |
| 41 | 41 | } |
| 42 | 42 | return $query.implode(",\n", $arr)."\n"; |
@@ -26,10 +26,10 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | protected function buildTables(string $query): string { |
| 28 | 28 | $arr = []; |
| 29 | - foreach($this->tables as $table) { |
|
| 29 | + foreach ($this->tables as $table) { |
|
| 30 | 30 | $arr[] = "\t".$this->buildTableName($table['alias'], $table['name']); |
| 31 | 31 | } |
| 32 | - if(count($arr)) { |
|
| 32 | + if (count($arr)) { |
|
| 33 | 33 | $query .= implode(",\n", $arr)."\n"; |
| 34 | 34 | } |
| 35 | 35 | return $query; |
@@ -31,13 +31,13 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | protected function buildFieldList(array $fields, array $query = []): array { |
| 33 | 33 | foreach ($fields as $fieldName => $fieldValue) { |
| 34 | - if($fieldValue instanceof DefaultValue) { |
|
| 34 | + if ($fieldValue instanceof DefaultValue) { |
|
| 35 | 35 | $fieldValue = 'DEFAULT'; |
| 36 | 36 | } |
| 37 | - if(is_array($this->mask) && !in_array($fieldName, $this->mask, true)) { |
|
| 37 | + if (is_array($this->mask) && !in_array($fieldName, $this->mask, true)) { |
|
| 38 | 38 | continue; |
| 39 | 39 | } |
| 40 | - if(is_int($fieldName)) { |
|
| 40 | + if (is_int($fieldName)) { |
|
| 41 | 41 | if (is_array($fieldValue)) { |
| 42 | 42 | $fieldValue = $this->db()->quoteExpression($fieldValue[0], array_slice($fieldValue, 1)); |
| 43 | 43 | } |