@@ -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; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * @return $this |
| 89 | 89 | */ |
| 90 | 90 | public function addExpr(string $str, ...$args) { |
| 91 | - if(count($args) > 0) { |
|
| 91 | + if (count($args) > 0) { |
|
| 92 | 92 | $this->fields[] = func_get_args(); |
| 93 | 93 | } else { |
| 94 | 94 | $this->fields[] = $str; |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @return $this |
| 103 | 103 | */ |
| 104 | 104 | public function updateExpr(string $str, ...$args) { |
| 105 | - if(count($args) > 0) { |
|
| 105 | + if (count($args) > 0) { |
|
| 106 | 106 | $this->update[] = func_get_args(); |
| 107 | 107 | } else { |
| 108 | 108 | $this->update[] = $str; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * @return $this |
| 117 | 117 | */ |
| 118 | 118 | public function addOrUpdateExpr(string $expr, ...$args) { |
| 119 | - if(count($args) > 0) { |
|
| 119 | + if (count($args) > 0) { |
|
| 120 | 120 | $this->fields[] = func_get_args(); |
| 121 | 121 | $this->update[] = func_get_args(); |
| 122 | 122 | } else { |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @return $this |
| 134 | 134 | */ |
| 135 | 135 | public function addAll(array $data, array $mask = null, array $excludeFields = null) { |
| 136 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
| 136 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
| 137 | 137 | $this->add($field, $value); |
| 138 | 138 | }); |
| 139 | 139 | return $this; |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | * @return $this |
| 147 | 147 | */ |
| 148 | 148 | public function updateAll(array $data, array $mask = null, array $excludeFields = null) { |
| 149 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
| 150 | - if($field !== $this->keyField) { |
|
| 149 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
| 150 | + if ($field !== $this->keyField) { |
|
| 151 | 151 | $this->update($field, $value); |
| 152 | 152 | } |
| 153 | 153 | }); |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @return string |
| 192 | 192 | */ |
| 193 | 193 | public function __toString(): string { |
| 194 | - if($this->table === null) { |
|
| 194 | + if ($this->table === null) { |
|
| 195 | 195 | throw new RuntimeException('Specify a table-name'); |
| 196 | 196 | } |
| 197 | 197 | |
@@ -201,21 +201,21 @@ discard block |
||
| 201 | 201 | $ignoreStr = $this->ignore ? ' IGNORE' : ''; |
| 202 | 202 | $queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n"; |
| 203 | 203 | |
| 204 | - if($this->from !== null) { |
|
| 204 | + if ($this->from !== null) { |
|
| 205 | 205 | $fields = $this->from->getFields(); |
| 206 | 206 | $queryArr[] = sprintf("\t(%s)\n", implode(', ', array_keys($fields))); |
| 207 | 207 | $queryArr[] = $this->from; |
| 208 | 208 | } else { |
| 209 | 209 | $fields = $this->fields; |
| 210 | 210 | $insertData = $this->buildFieldList($fields); |
| 211 | - if(!count($insertData)) { |
|
| 211 | + if (!count($insertData)) { |
|
| 212 | 212 | throw new RuntimeException('No field-data found'); |
| 213 | 213 | } |
| 214 | 214 | $queryArr[] = sprintf("SET\n%s\n", implode(",\n", $insertData)); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | $updateData = $this->buildUpdate(); |
| 218 | - if($updateData) { |
|
| 218 | + if ($updateData) { |
|
| 219 | 219 | $queryArr[] = "{$updateData}\n"; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | * @return array<string|int, mixed> |
| 230 | 230 | */ |
| 231 | 231 | private function addTo(array $fields, string $field, $value): array { |
| 232 | - if(!$this->isFieldNameValid($field)) { |
|
| 232 | + if (!$this->isFieldNameValid($field)) { |
|
| 233 | 233 | throw new UnexpectedValueException('Field name is invalid'); |
| 234 | 234 | } |
| 235 | 235 | $sqlField = $field; |
@@ -245,18 +245,18 @@ discard block |
||
| 245 | 245 | * @param callable(string, mixed): void $fn |
| 246 | 246 | */ |
| 247 | 247 | private function addAllTo(array $data, ?array $mask, ?array $excludeFields, callable $fn): void { |
| 248 | - if($mask !== null) { |
|
| 248 | + if ($mask !== null) { |
|
| 249 | 249 | $data = array_intersect_key($data, array_combine($mask, $mask)); |
| 250 | 250 | } |
| 251 | - if($excludeFields !== null) { |
|
| 252 | - foreach($excludeFields as $excludeField) { |
|
| 253 | - if(array_key_exists($excludeField, $data)) { |
|
| 251 | + if ($excludeFields !== null) { |
|
| 252 | + foreach ($excludeFields as $excludeField) { |
|
| 253 | + if (array_key_exists($excludeField, $data)) { |
|
| 254 | 254 | unset($data[$excludeField]); |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | $data = $this->clearValues($data); |
| 259 | - foreach($data as $field => $value) { |
|
| 259 | + foreach ($data as $field => $value) { |
|
| 260 | 260 | $fn($field, $value); |
| 261 | 261 | } |
| 262 | 262 | } |
@@ -266,10 +266,10 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | private function buildUpdate(): string { |
| 268 | 268 | $queryArr = []; |
| 269 | - if(!empty($this->update)) { |
|
| 269 | + if (!empty($this->update)) { |
|
| 270 | 270 | $queryArr[] = "ON DUPLICATE KEY UPDATE\n"; |
| 271 | 271 | $updateArr = []; |
| 272 | - if($this->keyField !== null) { |
|
| 272 | + if ($this->keyField !== null) { |
|
| 273 | 273 | $updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})"; |
| 274 | 274 | } |
| 275 | 275 | $updateArr = $this->buildFieldList($this->update, $updateArr); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | * @return array<string, mixed> |
| 293 | 293 | */ |
| 294 | 294 | private function clearValues(array $values): array { |
| 295 | - if(!count($values)) { |
|
| 295 | + if (!count($values)) { |
|
| 296 | 296 | return []; |
| 297 | 297 | } |
| 298 | 298 | |
@@ -300,8 +300,8 @@ discard block |
||
| 300 | 300 | $fields = $this->db()->getTableFields($tableName); |
| 301 | 301 | $result = []; |
| 302 | 302 | |
| 303 | - foreach($values as $fieldName => $fieldValue) { |
|
| 304 | - if(in_array($fieldName, $fields)) { |
|
| 303 | + foreach ($values as $fieldName => $fieldValue) { |
|
| 304 | + if (in_array($fieldName, $fields)) { |
|
| 305 | 305 | $result[$fieldName] = $fieldValue; |
| 306 | 306 | } |
| 307 | 307 | } |
@@ -122,7 +122,7 @@ |
||
| 122 | 122 | * @return $this |
| 123 | 123 | */ |
| 124 | 124 | public function from(?string $alias, $table = null): self { |
| 125 | - if($table === null) { |
|
| 125 | + if ($table === null) { |
|
| 126 | 126 | [$alias, $table] = [$table, $alias]; |
| 127 | 127 | $this->addTable($alias, (string) $table); |
| 128 | 128 | } else { |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return $this |
| 30 | 30 | */ |
| 31 | 31 | public function table(string $alias, $table = null): self { |
| 32 | - if($table === null) { |
|
| 32 | + if ($table === null) { |
|
| 33 | 33 | [$alias, $table] = [$table, $alias]; |
| 34 | 34 | } |
| 35 | 35 | $this->addTable($alias, $table); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return $this |
| 65 | 65 | */ |
| 66 | 66 | public function setExpr(string $expr, ...$args): self { |
| 67 | - if(count($args) > 0) { |
|
| 67 | + if (count($args) > 0) { |
|
| 68 | 68 | $this->fields[] = func_get_args(); |
| 69 | 69 | } else { |
| 70 | 70 | $this->fields[] = $expr; |
@@ -78,15 +78,15 @@ discard block |
||
| 78 | 78 | * @return $this |
| 79 | 79 | */ |
| 80 | 80 | public function setAll(array $data, array $allowedFields = null): self { |
| 81 | - if($allowedFields !== null) { |
|
| 82 | - foreach($data as $fieldName => $value) { |
|
| 83 | - if(in_array($fieldName, $allowedFields)) { |
|
| 81 | + if ($allowedFields !== null) { |
|
| 82 | + foreach ($data as $fieldName => $value) { |
|
| 83 | + if (in_array($fieldName, $allowedFields)) { |
|
| 84 | 84 | $this->set($fieldName, $value); |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | } else { |
| 88 | 88 | $values = $this->clearValues($data); |
| 89 | - foreach($values as $fieldName => $value) { |
|
| 89 | + foreach ($values as $fieldName => $value) { |
|
| 90 | 90 | $this->set($fieldName, $value); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | private function buildAssignments(string $query): string { |
| 123 | 123 | $sqlFields = $this->buildFieldList($this->fields); |
| 124 | - if(!count($sqlFields)) { |
|
| 124 | + if (!count($sqlFields)) { |
|
| 125 | 125 | throw new RuntimeException('No field-data found'); |
| 126 | 126 | } |
| 127 | 127 | return sprintf("%s%s\n", $query, implode(",\n", $sqlFields)); |
@@ -132,14 +132,14 @@ discard block |
||
| 132 | 132 | * @return array<string, mixed> |
| 133 | 133 | */ |
| 134 | 134 | private function clearValues(array $values): array { |
| 135 | - if(!count($values)) { |
|
| 135 | + if (!count($values)) { |
|
| 136 | 136 | return []; |
| 137 | 137 | } |
| 138 | 138 | $tables = $this->getTables(); |
| 139 | - if(!count($tables)) { |
|
| 139 | + if (!count($tables)) { |
|
| 140 | 140 | throw new RuntimeException('Table name is missing'); |
| 141 | 141 | } |
| 142 | - if(count($tables) > 1) { |
|
| 142 | + if (count($tables) > 1) { |
|
| 143 | 143 | throw new RuntimeException('Batch values only work with max. one table'); |
| 144 | 144 | } |
| 145 | 145 | |
@@ -147,11 +147,11 @@ discard block |
||
| 147 | 147 | $tableName = $table['name']; |
| 148 | 148 | |
| 149 | 149 | $result = []; |
| 150 | - if(is_string($tableName)) { |
|
| 150 | + if (is_string($tableName)) { |
|
| 151 | 151 | $fields = $this->db()->getTableFields($tableName); |
| 152 | 152 | |
| 153 | - foreach($values as $fieldName => $fieldValue) { |
|
| 154 | - if(in_array($fieldName, $fields, true)) { |
|
| 153 | + foreach ($values as $fieldName => $fieldValue) { |
|
| 154 | + if (in_array($fieldName, $fields, true)) { |
|
| 155 | 155 | $result[$fieldName] = $fieldValue; |
| 156 | 156 | } |
| 157 | 157 | } |
@@ -29,14 +29,14 @@ |
||
| 29 | 29 | * @return $this |
| 30 | 30 | */ |
| 31 | 31 | public function debug($stop = true) { |
| 32 | - if(array_key_exists('debug_formatter', $this->options)) { |
|
| 32 | + if (array_key_exists('debug_formatter', $this->options)) { |
|
| 33 | 33 | $this->options['debug_formatter'](); |
| 34 | - } elseif(PHP_SAPI === 'cli') { |
|
| 34 | + } elseif (PHP_SAPI === 'cli') { |
|
| 35 | 35 | echo "\n{$this->__toString()}\n"; |
| 36 | 36 | } else { |
| 37 | 37 | echo "<pre>{$this->__toString()}</pre>"; |
| 38 | 38 | } |
| 39 | - if($stop) { |
|
| 39 | + if ($stop) { |
|
| 40 | 40 | exit; |
| 41 | 41 | } |
| 42 | 42 | return $this; |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param array<string, mixed> $options |
| 43 | 43 | */ |
| 44 | 44 | public function __construct(PDO $pdo, array $options = []) { |
| 45 | - if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 45 | + if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 46 | 46 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 47 | 47 | } |
| 48 | 48 | $this->pdo = $pdo; |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @return VirtualTables |
| 77 | 77 | */ |
| 78 | 78 | public function getVirtualTables(): VirtualTables { |
| 79 | - if($this->virtualTables === null) { |
|
| 79 | + if ($this->virtualTables === null) { |
|
| 80 | 80 | $this->virtualTables = new VirtualTables(); |
| 81 | 81 | } |
| 82 | 82 | return $this->virtualTables; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @return QueryStatement |
| 88 | 88 | */ |
| 89 | 89 | public function query(string $query) { |
| 90 | - return $this->buildQueryStatement($query, function ($query) { |
|
| 90 | + return $this->buildQueryStatement($query, function($query) { |
|
| 91 | 91 | return $this->pdo->query($query); |
| 92 | 92 | }); |
| 93 | 93 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @return QueryStatement |
| 98 | 98 | */ |
| 99 | 99 | public function prepare(string $query) { |
| 100 | - return $this->buildQueryStatement($query, function ($query) { |
|
| 100 | + return $this->buildQueryStatement($query, function($query) { |
|
| 101 | 101 | return $this->pdo->prepare($query); |
| 102 | 102 | }); |
| 103 | 103 | } |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @return int |
| 109 | 109 | */ |
| 110 | 110 | public function exec(string $query, array $params = []): int { |
| 111 | - return $this->exceptionHandler(function () use ($query, $params) { |
|
| 111 | + return $this->exceptionHandler(function() use ($query, $params) { |
|
| 112 | 112 | $stmt = $this->pdo->prepare($query); |
| 113 | 113 | $timer = microtime(true); |
| 114 | 114 | $stmt->execute($params); |
| 115 | - $this->queryLoggers->log($query, microtime(true) - $timer); |
|
| 115 | + $this->queryLoggers->log($query, microtime(true)-$timer); |
|
| 116 | 116 | $result = $stmt->rowCount(); |
| 117 | 117 | $stmt->closeCursor(); |
| 118 | 118 | return $result; |
@@ -133,15 +133,15 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function getTableFields(string $table): array { |
| 135 | 135 | $table = $this->select()->aliasReplacer()->replace($table); |
| 136 | - if(array_key_exists($table, $this->tableFields)) { |
|
| 136 | + if (array_key_exists($table, $this->tableFields)) { |
|
| 137 | 137 | return $this->tableFields[$table]; |
| 138 | 138 | } |
| 139 | 139 | $stmt = $this->pdo->query("DESCRIBE {$table}"); |
| 140 | - if($stmt === false) { |
|
| 140 | + if ($stmt === false) { |
|
| 141 | 141 | throw new RuntimeException('Invalid return type'); |
| 142 | 142 | } |
| 143 | 143 | $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 144 | - $this->tableFields[$table] = array_map(static function ($row) { return $row['Field']; }, $rows ?: []); |
|
| 144 | + $this->tableFields[$table] = array_map(static function($row) { return $row['Field']; }, $rows ?: []); |
|
| 145 | 145 | $stmt->closeCursor(); |
| 146 | 146 | return $this->tableFields[$table]; |
| 147 | 147 | } |
@@ -153,12 +153,12 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function quoteExpression(string $expression, array $arguments = []): string { |
| 155 | 155 | $index = -1; |
| 156 | - $func = function () use ($arguments, &$index) { |
|
| 156 | + $func = function() use ($arguments, &$index) { |
|
| 157 | 157 | $index++; |
| 158 | - if(array_key_exists($index, $arguments)) { |
|
| 158 | + if (array_key_exists($index, $arguments)) { |
|
| 159 | 159 | $argument = $arguments[$index]; |
| 160 | 160 | $value = $this->quote($argument); |
| 161 | - } elseif(count($arguments) > 0) { |
|
| 161 | + } elseif (count($arguments) > 0) { |
|
| 162 | 162 | $args = $arguments; |
| 163 | 163 | $value = array_pop($args); |
| 164 | 164 | $value = $this->quote($value); |
@@ -176,15 +176,15 @@ discard block |
||
| 176 | 176 | * @return string |
| 177 | 177 | */ |
| 178 | 178 | public function quote($value): string { |
| 179 | - if(is_null($value)) { |
|
| 179 | + if (is_null($value)) { |
|
| 180 | 180 | $result = 'NULL'; |
| 181 | - } elseif($value instanceof Builder\DBExpr) { |
|
| 181 | + } elseif ($value instanceof Builder\DBExpr) { |
|
| 182 | 182 | $result = $value->getExpression(); |
| 183 | - } elseif($value instanceof Builder\Select) { |
|
| 183 | + } elseif ($value instanceof Builder\Select) { |
|
| 184 | 184 | $result = sprintf('(%s)', (string) $value); |
| 185 | - } elseif(is_array($value)) { |
|
| 186 | - $result = implode(', ', array_map(function ($value) { return $this->quote($value); }, $value)); |
|
| 187 | - } elseif(is_int($value) || is_float($value)) { |
|
| 185 | + } elseif (is_array($value)) { |
|
| 186 | + $result = implode(', ', array_map(function($value) { return $this->quote($value); }, $value)); |
|
| 187 | + } elseif (is_int($value) || is_float($value)) { |
|
| 188 | 188 | $result = (string) $value; |
| 189 | 189 | } else { |
| 190 | 190 | $result = $this->pdo->quote($value); |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | if (is_numeric($field) || !is_string($field)) { |
| 201 | 201 | throw new UnexpectedValueException('Field name is invalid'); |
| 202 | 202 | } |
| 203 | - if(strpos($field, '`') !== false) { |
|
| 203 | + if (strpos($field, '`') !== false) { |
|
| 204 | 204 | return $field; |
| 205 | 205 | } |
| 206 | 206 | $parts = explode('.', $field); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $select = array_key_exists('select-factory', $this->options) |
| 216 | 216 | ? call_user_func($this->options['select-factory'], $this, $this->options['select-options']) |
| 217 | 217 | : new Builder\RunnableSelect($this, $this->options['select-options']); |
| 218 | - if($fields !== null) { |
|
| 218 | + if ($fields !== null) { |
|
| 219 | 219 | $select->fields($fields); |
| 220 | 220 | } |
| 221 | 221 | return $select; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | $insert = array_key_exists('insert-factory', $this->options) |
| 230 | 230 | ? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options']) |
| 231 | 231 | : new Builder\RunnableInsert($this, $this->options['insert-options']); |
| 232 | - if($fields !== null) { |
|
| 232 | + if ($fields !== null) { |
|
| 233 | 233 | $insert->addAll($fields); |
| 234 | 234 | } |
| 235 | 235 | return $insert; |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $update = array_key_exists('update-factory', $this->options) |
| 244 | 244 | ? call_user_func($this->options['update-factory'], $this, $this->options['update-options']) |
| 245 | 245 | : new Builder\RunnableUpdate($this, $this->options['update-options']); |
| 246 | - if($fields !== null) { |
|
| 246 | + if ($fields !== null) { |
|
| 247 | 247 | $update->setAll($fields); |
| 248 | 248 | } |
| 249 | 249 | return $update; |
@@ -262,8 +262,8 @@ discard block |
||
| 262 | 262 | * @return $this |
| 263 | 263 | */ |
| 264 | 264 | public function transactionStart() { |
| 265 | - if($this->transactionLevel === 0) { |
|
| 266 | - if($this->pdo->inTransaction()) { |
|
| 265 | + if ($this->transactionLevel === 0) { |
|
| 266 | + if ($this->pdo->inTransaction()) { |
|
| 267 | 267 | $this->outerTransaction = true; |
| 268 | 268 | } else { |
| 269 | 269 | $this->pdo->beginTransaction(); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | * @return $this |
| 278 | 278 | */ |
| 279 | 279 | public function transactionCommit() { |
| 280 | - return $this->transactionEnd(function () { |
|
| 280 | + return $this->transactionEnd(function() { |
|
| 281 | 281 | $this->pdo->commit(); |
| 282 | 282 | }); |
| 283 | 283 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * @return $this |
| 287 | 287 | */ |
| 288 | 288 | public function transactionRollback() { |
| 289 | - return $this->transactionEnd(function () { |
|
| 289 | + return $this->transactionEnd(function() { |
|
| 290 | 290 | $this->pdo->rollBack(); |
| 291 | 291 | }); |
| 292 | 292 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @return T |
| 298 | 298 | */ |
| 299 | 299 | public function dryRun(callable $callback) { |
| 300 | - if(!$this->pdo->inTransaction()) { |
|
| 300 | + if (!$this->pdo->inTransaction()) { |
|
| 301 | 301 | $this->transactionStart(); |
| 302 | 302 | try { |
| 303 | 303 | return $callback($this); |
@@ -322,14 +322,14 @@ discard block |
||
| 322 | 322 | * @throws Throwable |
| 323 | 323 | */ |
| 324 | 324 | public function transaction(callable $callback) { |
| 325 | - if(!$this->pdo->inTransaction()) { |
|
| 325 | + if (!$this->pdo->inTransaction()) { |
|
| 326 | 326 | $this->transactionStart(); |
| 327 | 327 | try { |
| 328 | 328 | $result = $callback($this); |
| 329 | 329 | $this->transactionCommit(); |
| 330 | 330 | return $result; |
| 331 | 331 | } catch (Throwable $e) { |
| 332 | - if($this->pdo->inTransaction()) { |
|
| 332 | + if ($this->pdo->inTransaction()) { |
|
| 333 | 333 | $this->transactionRollback(); |
| 334 | 334 | } |
| 335 | 335 | throw $e; |
@@ -353,11 +353,11 @@ discard block |
||
| 353 | 353 | */ |
| 354 | 354 | private function transactionEnd(callable $fn): self { |
| 355 | 355 | $this->transactionLevel--; |
| 356 | - if($this->transactionLevel < 0) { |
|
| 356 | + if ($this->transactionLevel < 0) { |
|
| 357 | 357 | throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
| 358 | 358 | } |
| 359 | - if($this->transactionLevel < 1) { |
|
| 360 | - if($this->outerTransaction) { |
|
| 359 | + if ($this->transactionLevel < 1) { |
|
| 360 | + if ($this->outerTransaction) { |
|
| 361 | 361 | $this->outerTransaction = false; |
| 362 | 362 | } else { |
| 363 | 363 | $fn(); |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | */ |
| 375 | 375 | private function buildQueryStatement(string $query, callable $fn): QueryStatement { |
| 376 | 376 | $stmt = $fn($query); |
| 377 | - if(!$stmt) { |
|
| 377 | + if (!$stmt) { |
|
| 378 | 378 | throw new RuntimeException("Could not execute statement:\n{$query}"); |
| 379 | 379 | } |
| 380 | 380 | return new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |