@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @inheritDoc |
| 87 | 87 | */ |
| 88 | 88 | public function fetchRowsLazy($callback = null) { |
| 89 | - $callback = $callback ?? (static function ($row) { return $row; }); |
|
| 89 | + $callback = $callback ?? (static function($row) { return $row; }); |
|
| 90 | 90 | yield from $this->fetchLazy($callback, PDO::FETCH_ASSOC); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | * @inheritDoc |
| 95 | 95 | */ |
| 96 | 96 | public function fetchRow($callback = null): array { |
| 97 | - $callback = $callback ?? (static function ($row) { return $row; }); |
|
| 98 | - return $this->fetch($callback, PDO::FETCH_ASSOC, null, static function ($row) { |
|
| 97 | + $callback = $callback ?? (static function($row) { return $row; }); |
|
| 98 | + return $this->fetch($callback, PDO::FETCH_ASSOC, null, static function($row) { |
|
| 99 | 99 | return ['valid' => is_array($row), 'default' => []]; |
| 100 | 100 | }); |
| 101 | 101 | } |
@@ -104,17 +104,17 @@ discard block |
||
| 104 | 104 | * @inheritDoc |
| 105 | 105 | */ |
| 106 | 106 | public function fetchObjects(string $className = 'stdClass', $callback = null): array { |
| 107 | - return $this->createTempStatement(function (QueryStatement $statement) use ($className, $callback) { |
|
| 107 | + return $this->createTempStatement(function(QueryStatement $statement) use ($className, $callback) { |
|
| 108 | 108 | $data = $statement->fetchAll(PDO::FETCH_CLASS, $className); |
| 109 | - if($this->preserveTypes) { |
|
| 109 | + if ($this->preserveTypes) { |
|
| 110 | 110 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 111 | - $data = array_map(static function ($row) use ($columnDefinitions) { return FieldValueConverter::convertValues($row, $columnDefinitions); }, $data); |
|
| 111 | + $data = array_map(static function($row) use ($columnDefinitions) { return FieldValueConverter::convertValues($row, $columnDefinitions); }, $data); |
|
| 112 | 112 | } |
| 113 | - if($callback !== null) { |
|
| 114 | - return call_user_func(static function ($resultData = []) use ($data, $callback) { |
|
| 115 | - foreach($data as $row) { |
|
| 113 | + if ($callback !== null) { |
|
| 114 | + return call_user_func(static function($resultData = []) use ($data, $callback) { |
|
| 115 | + foreach ($data as $row) { |
|
| 116 | 116 | $result = $callback($row); |
| 117 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
| 117 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
| 118 | 118 | $resultData[] = $result; |
| 119 | 119 | } else { |
| 120 | 120 | $resultData[] = $row; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @inheritDoc |
| 132 | 132 | */ |
| 133 | 133 | public function fetchObjectsLazy($className = null, $callback = null) { |
| 134 | - $callback = $callback ?? (static function ($row) { return $row; }); |
|
| 134 | + $callback = $callback ?? (static function($row) { return $row; }); |
|
| 135 | 135 | yield from $this->fetchLazy($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | * @inheritDoc |
| 140 | 140 | */ |
| 141 | 141 | public function fetchObject($className = null, $callback = null) { |
| 142 | - $callback = $callback ?? (static function ($row) { return $row; }); |
|
| 143 | - return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, static function ($row) { |
|
| 142 | + $callback = $callback ?? (static function($row) { return $row; }); |
|
| 143 | + return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, static function($row) { |
|
| 144 | 144 | return ['valid' => is_object($row), 'default' => null]; |
| 145 | 145 | }); |
| 146 | 146 | } |
@@ -149,11 +149,11 @@ discard block |
||
| 149 | 149 | * @inheritDoc |
| 150 | 150 | */ |
| 151 | 151 | public function fetchKeyValue($treatValueAsArray = false): array { |
| 152 | - return $this->createTempStatement(static function (QueryStatement $statement) use ($treatValueAsArray) { |
|
| 153 | - if($treatValueAsArray) { |
|
| 152 | + return $this->createTempStatement(static function(QueryStatement $statement) use ($treatValueAsArray) { |
|
| 153 | + if ($treatValueAsArray) { |
|
| 154 | 154 | $rows = $statement->fetchAll(PDO::FETCH_ASSOC); |
| 155 | 155 | $result = []; |
| 156 | - foreach($rows as $row) { |
|
| 156 | + foreach ($rows as $row) { |
|
| 157 | 157 | [$key] = array_values($row); |
| 158 | 158 | $result[$key] = $row; |
| 159 | 159 | } |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | public function fetchGroups(array $fields): array { |
| 170 | 170 | $rows = $this->fetchRows(); |
| 171 | 171 | $result = []; |
| 172 | - foreach($rows as $row) { |
|
| 172 | + foreach ($rows as $row) { |
|
| 173 | 173 | /** @var array<string, mixed> $tmp */ |
| 174 | 174 | $tmp = &$result; |
| 175 | - foreach($fields as $field) { |
|
| 175 | + foreach ($fields as $field) { |
|
| 176 | 176 | $value = (string) $row[$field]; |
| 177 | - if(!array_key_exists($value, $tmp)) { |
|
| 177 | + if (!array_key_exists($value, $tmp)) { |
|
| 178 | 178 | $tmp[$value] = []; |
| 179 | 179 | } |
| 180 | 180 | $tmp = &$tmp[$value]; |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * @inheritDoc |
| 189 | 189 | */ |
| 190 | 190 | public function fetchArray(?callable $fn = null): array { |
| 191 | - return $this->createTempStatement(static function (QueryStatement $stmt) use ($fn) { |
|
| 192 | - if($fn !== null) { |
|
| 191 | + return $this->createTempStatement(static function(QueryStatement $stmt) use ($fn) { |
|
| 192 | + if ($fn !== null) { |
|
| 193 | 193 | return $stmt->fetchAll(PDO::FETCH_FUNC, $fn); |
| 194 | 194 | } |
| 195 | 195 | return $stmt->fetchAll(PDO::FETCH_COLUMN); |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | * @inheritDoc |
| 201 | 201 | */ |
| 202 | 202 | public function fetchValue($default = null, ?callable $fn = null) { |
| 203 | - return $this->createTempStatement(static function (QueryStatement $stmt) use ($default, $fn) { |
|
| 203 | + return $this->createTempStatement(static function(QueryStatement $stmt) use ($default, $fn) { |
|
| 204 | 204 | $result = $stmt->fetchAll(PDO::FETCH_COLUMN); |
| 205 | - if($result !== false && array_key_exists(0, $result)) { |
|
| 205 | + if ($result !== false && array_key_exists(0, $result)) { |
|
| 206 | 206 | return $fn !== null ? $fn($result[0]) : $result[0]; |
| 207 | 207 | } |
| 208 | 208 | return $default; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | $query = $this->__toString(); |
| 238 | 238 | $statement = $db->prepare($query); |
| 239 | 239 | $statement->execute($this->values); |
| 240 | - if($this->getCalcFoundRows()) { |
|
| 240 | + if ($this->getCalcFoundRows()) { |
|
| 241 | 241 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
| 242 | 242 | } |
| 243 | 243 | return $statement; |
@@ -259,21 +259,21 @@ discard block |
||
| 259 | 259 | * @return ($callback is null ? array<int, ($mode is PDO::FETCH_NUM ? array<int, null|scalar> : array<string, null|scalar>)> : array<int, TFnReturnType|TFnParamType>) |
| 260 | 260 | */ |
| 261 | 261 | private function fetchAll($callback = null, int $mode = 0, $arg0 = null) { |
| 262 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
| 262 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
| 263 | 263 | $statement->setFetchMode($mode, $arg0); |
| 264 | 264 | $data = $statement->fetchAll(); |
| 265 | - if($this->preserveTypes) { |
|
| 265 | + if ($this->preserveTypes) { |
|
| 266 | 266 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 267 | - $data = array_map(static function ($row) use ($columnDefinitions) { return FieldValueConverter::convertValues($row, $columnDefinitions); }, $data); |
|
| 267 | + $data = array_map(static function($row) use ($columnDefinitions) { return FieldValueConverter::convertValues($row, $columnDefinitions); }, $data); |
|
| 268 | 268 | } |
| 269 | - if($callback !== null) { |
|
| 270 | - return call_user_func(static function ($resultData = []) use ($data, $callback) { |
|
| 271 | - foreach($data as $row) { |
|
| 269 | + if ($callback !== null) { |
|
| 270 | + return call_user_func(static function($resultData = []) use ($data, $callback) { |
|
| 271 | + foreach ($data as $row) { |
|
| 272 | 272 | $result = $callback($row); |
| 273 | - if($result instanceof DBIgnoreRow) { |
|
| 273 | + if ($result instanceof DBIgnoreRow) { |
|
| 274 | 274 | continue; |
| 275 | 275 | } |
| 276 | - if($result !== null) { |
|
| 276 | + if ($result !== null) { |
|
| 277 | 277 | $resultData[] = $result; |
| 278 | 278 | } else { |
| 279 | 279 | $resultData[] = $row; |
@@ -298,18 +298,18 @@ discard block |
||
| 298 | 298 | $statement = $this->createStatement(); |
| 299 | 299 | $statement->setFetchMode($mode, $arg0); |
| 300 | 300 | try { |
| 301 | - while($row = $statement->fetch()) { |
|
| 301 | + while ($row = $statement->fetch()) { |
|
| 302 | 302 | /** @var T $row */ |
| 303 | 303 | // if($this->preserveTypes) { |
| 304 | 304 | // $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 305 | 305 | // $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 306 | 306 | // } |
| 307 | 307 | $result = $callback($row); |
| 308 | - if($result instanceof DBIgnoreRow) { |
|
| 308 | + if ($result instanceof DBIgnoreRow) { |
|
| 309 | 309 | // Skip row in this case |
| 310 | 310 | continue; |
| 311 | 311 | } |
| 312 | - if($result !== null) { |
|
| 312 | + if ($result !== null) { |
|
| 313 | 313 | yield $result; |
| 314 | 314 | } else { |
| 315 | 315 | yield $row; |
@@ -330,20 +330,20 @@ discard block |
||
| 330 | 330 | * @return T|U|array<string, mixed> |
| 331 | 331 | */ |
| 332 | 332 | private function fetch($callback, int $mode = PDO::FETCH_ASSOC, $arg0 = null, Closure $resultValidator = null) { |
| 333 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
| 333 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
| 334 | 334 | $statement->setFetchMode($mode, $arg0); |
| 335 | 335 | $row = $statement->fetch(); |
| 336 | 336 | $result = $resultValidator === null ? ['valid' => true] : $resultValidator($row); |
| 337 | - if(!$result['valid']) { |
|
| 337 | + if (!$result['valid']) { |
|
| 338 | 338 | return $result['default']; |
| 339 | 339 | } |
| 340 | - if($this->preserveTypes) { |
|
| 340 | + if ($this->preserveTypes) { |
|
| 341 | 341 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
| 342 | 342 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
| 343 | 343 | } |
| 344 | - if($callback !== null) { |
|
| 344 | + if ($callback !== null) { |
|
| 345 | 345 | $result = $callback($row); |
| 346 | - if($result !== null) { |
|
| 346 | + if ($result !== null) { |
|
| 347 | 347 | $row = $result; |
| 348 | 348 | } |
| 349 | 349 | } |
@@ -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); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $this->exceptionHandler(function() use ($params) { |
| 67 | 67 | $this->queryLoggers->logRegion($this->query, function() use ($params) { |
| 68 | 68 | $response = $this->statement->execute($params); |
| 69 | - if(!$response) { |
|
| 69 | + if (!$response) { |
|
| 70 | 70 | throw new SqlException('Execution returned with "false".'); |
| 71 | 71 | } |
| 72 | 72 | }); |
@@ -82,13 +82,13 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null, array $ctorArgs = []): array { |
| 84 | 84 | $result = $x = $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); |
| 89 | 89 | }); |
| 90 | 90 | /** @var array<mixed, mixed>|false $x */ |
| 91 | - if($x === false) { |
|
| 91 | + if ($x === false) { |
|
| 92 | 92 | return []; |
| 93 | 93 | } |
| 94 | 94 | return $result; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | public function getColumnMeta(int $columnNo): ?array { |
| 142 | 142 | return $this->exceptionHandler(function() use ($columnNo) { |
| 143 | 143 | $columnMeta = $this->statement->getColumnMeta($columnNo); |
| 144 | - if($columnMeta === false) { |
|
| 144 | + if ($columnMeta === false) { |
|
| 145 | 145 | return null; |
| 146 | 146 | } |
| 147 | 147 | return $columnMeta; |