@@ -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 | } |
@@ -29,10 +29,10 @@ 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 | - if($table === null) { |
|
| 35 | + if ($table === null) { |
|
| 36 | 36 | [$alias, $table] = [$table, $alias]; |
| 37 | 37 | } |
| 38 | 38 | $this->addTable($alias, $table); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | public function __toString(): string { |
| 52 | 52 | $query = "DELETE "; |
| 53 | 53 | $query .= implode(', ', $this->aliases); |
| 54 | - $query = trim($query) . " FROM\n"; |
|
| 54 | + $query = trim($query)." FROM\n"; |
|
| 55 | 55 | $query = $this->buildTables($query); |
| 56 | 56 | $query = $this->buildJoins($query); |
| 57 | 57 | $query = $this->buildWhereConditions($query); |
@@ -10,13 +10,13 @@ discard block |
||
| 10 | 10 | * @param array<int, mixed> $args |
| 11 | 11 | */ |
| 12 | 12 | public static function addCondition(callable $addFn, $expression, array $args): void { |
| 13 | - if($expression instanceof OptionalExpression) { |
|
| 14 | - if($expression->isValid()) { |
|
| 13 | + if ($expression instanceof OptionalExpression) { |
|
| 14 | + if ($expression->isValid()) { |
|
| 15 | 15 | $addFn($expression->getExpression(), [$expression->getValue()]); |
| 16 | 16 | } |
| 17 | - } elseif(is_object($expression)) { |
|
| 17 | + } elseif (is_object($expression)) { |
|
| 18 | 18 | self::addAsArray($addFn, (array) $expression, $args); |
| 19 | - } elseif(is_array($expression)) { |
|
| 19 | + } elseif (is_array($expression)) { |
|
| 20 | 20 | self::addAsArray($addFn, $expression, $args); |
| 21 | 21 | } else { |
| 22 | 22 | $addFn($expression, $args); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param array<int, mixed> $args |
| 30 | 30 | */ |
| 31 | 31 | private static function addAsArray(callable $addFn, array $expression, array $args): void { |
| 32 | - if(count($expression) > 0) { |
|
| 32 | + if (count($expression) > 0) { |
|
| 33 | 33 | $addFn($expression, $args); |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | public static function convertValues(array $row, array $columnDefinitions): array { |
| 11 | 11 | $result = []; |
| 12 | - foreach($row as $key => $value) { |
|
| 13 | - if($value !== null) { |
|
| 12 | + foreach ($row as $key => $value) { |
|
| 13 | + if ($value !== null) { |
|
| 14 | 14 | $result[$key] = self::convertValue($value, $columnDefinitions[$key]); |
| 15 | 15 | } else { |
| 16 | 16 | $result[$key] = $value; |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | public static function getFieldTypes(QueryStatement $statement): array { |
| 12 | 12 | $fieldTypes = []; |
| 13 | - for($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
| 13 | + for ($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
| 14 | 14 | $fieldTypes[(string) $column['name']] = self::getTypeFromNativeType($column['native_type']); |
| 15 | 15 | } |
| 16 | 16 | return $fieldTypes; |
@@ -13,15 +13,15 @@ |
||
| 13 | 13 | * @return string |
| 14 | 14 | */ |
| 15 | 15 | public static function build(Database $db, string $query, array $conditions, string $token): string { |
| 16 | - if(!count($conditions)) { |
|
| 16 | + if (!count($conditions)) { |
|
| 17 | 17 | return $query; |
| 18 | 18 | } |
| 19 | 19 | $query .= "{$token}\n"; |
| 20 | 20 | $arr = []; |
| 21 | - foreach($conditions as [$expression, $arguments]) { |
|
| 22 | - if(is_array($expression)) { |
|
| 23 | - foreach($expression as $key => $value) { |
|
| 24 | - if($value === null) { |
|
| 21 | + foreach ($conditions as [$expression, $arguments]) { |
|
| 22 | + if (is_array($expression)) { |
|
| 23 | + foreach ($expression as $key => $value) { |
|
| 24 | + if ($value === null) { |
|
| 25 | 25 | $arr = self::buildCondition($arr, "ISNULL(`{$key}`)", [$value], $db); |
| 26 | 26 | } else { |
| 27 | 27 | $arr = self::buildCondition($arr, "`{$key}`=?", [$value], $db); |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | public function run(array $params = []) { |
| 29 | 29 | $this->query->execute($params); |
| 30 | 30 | $response = $this->query->getStatement()->rowCount(); |
| 31 | - if($this->callbackFn !== null) { |
|
| 31 | + if ($this->callbackFn !== null) { |
|
| 32 | 32 | $response = call_user_func($this->callbackFn); |
| 33 | 33 | } |
| 34 | 34 | return $response; |