@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | if ($temp) { |
| 33 | 33 | $temp = $temp->fetch_fields(); |
| 34 | 34 | if ($temp) { |
| 35 | - $columns = array_map(function ($v) { |
|
| 35 | + $columns = array_map(function($v) { |
|
| 36 | 36 | return $v->name; |
| 37 | 37 | }, $temp); |
| 38 | 38 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | public function affected() : int |
| 53 | 53 | { |
| 54 | - return (int)$this->statement->affected_rows; |
|
| 54 | + return (int) $this->statement->affected_rows; |
|
| 55 | 55 | } |
| 56 | 56 | public function insertID(?string $sequence = null): mixed |
| 57 | 57 | { |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | public function current(): mixed |
| 75 | 75 | { |
| 76 | - return $this->nativeDriver ? $this->last : array_map(function ($v) { |
|
| 76 | + return $this->nativeDriver ? $this->last : array_map(function($v) { |
|
| 77 | 77 | return $v; |
| 78 | 78 | }, $this->row); |
| 79 | 79 | } |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | public function next(): void |
| 94 | 94 | { |
| 95 | - $this->fetched ++; |
|
| 96 | - $this->last = $this->nativeDriver ? ($this->result->fetch_assoc()?:null) : $this->statement->fetch(); |
|
| 95 | + $this->fetched++; |
|
| 96 | + $this->last = $this->nativeDriver ? ($this->result->fetch_assoc() ?: null) : $this->statement->fetch(); |
|
| 97 | 97 | } |
| 98 | 98 | public function valid(): bool |
| 99 | 99 | { |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | } |
| 25 | 25 | public function affected() : int |
| 26 | 26 | { |
| 27 | - return (int)\oci_num_rows($this->statement); |
|
| 27 | + return (int) \oci_num_rows($this->statement); |
|
| 28 | 28 | } |
| 29 | 29 | public function insertID(?string $sequence = null): mixed |
| 30 | 30 | { |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function count(): int |
| 39 | 39 | { |
| 40 | - return (int)\oci_num_rows($this->statement); |
|
| 40 | + return (int) \oci_num_rows($this->statement); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function key(): mixed |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | public function next(): void |
| 67 | 67 | { |
| 68 | - $this->fetched ++; |
|
| 69 | - $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC + \OCI_RETURN_NULLS + \OCI_RETURN_LOBS)?:null; |
|
| 68 | + $this->fetched++; |
|
| 69 | + $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC +\OCI_RETURN_NULLS +\OCI_RETURN_LOBS) ?: null; |
|
| 70 | 70 | if (is_array($this->last)) { |
| 71 | 71 | $this->cast(); |
| 72 | 72 | } |
@@ -78,23 +78,23 @@ discard block |
||
| 78 | 78 | protected function cast(): void |
| 79 | 79 | { |
| 80 | 80 | if (!count($this->types)) { |
| 81 | - foreach (array_keys($this->last??[]) as $k => $v) { |
|
| 81 | + foreach (array_keys($this->last ?? []) as $k => $v) { |
|
| 82 | 82 | $this->types[$v] = \oci_field_type($this->statement, $k + 1); |
| 83 | 83 | if ($this->types[$v] === 'NUMBER') { |
| 84 | 84 | $scale = \oci_field_scale($this->statement, $k + 1); |
| 85 | 85 | $precision = \oci_field_precision($this->statement, $k + 1); |
| 86 | 86 | // true float |
| 87 | - if ((int)$scale === -127 && (int)$precision !== 0) { |
|
| 87 | + if ((int) $scale === -127 && (int) $precision !== 0) { |
|
| 88 | 88 | $this->types[$v] = 'FLOAT'; |
| 89 | 89 | } |
| 90 | 90 | // TODO: decimal |
| 91 | - if ((int)$scale > 0) { |
|
| 91 | + if ((int) $scale > 0) { |
|
| 92 | 92 | $this->types[$v] = 'DECIMAL'; |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | - foreach ($this->last??[] as $k => $v) { |
|
| 97 | + foreach ($this->last ?? [] as $k => $v) { |
|
| 98 | 98 | if (!isset($this->types[$k])) { |
| 99 | 99 | continue; |
| 100 | 100 | } |
@@ -109,10 +109,10 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | switch ($this->types[$k]) { |
| 111 | 111 | case 'NUMBER': |
| 112 | - $this->last[$k] = (int)$v; |
|
| 112 | + $this->last[$k] = (int) $v; |
|
| 113 | 113 | break; |
| 114 | 114 | case 'FLOAT': |
| 115 | - $this->last[$k] = (float)$v; |
|
| 115 | + $this->last[$k] = (float) $v; |
|
| 116 | 116 | break; |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | * @param array|string $column either a single column name or an array of column names |
| 85 | 85 | * @return static |
| 86 | 86 | */ |
| 87 | - public function setPrimaryKey(array|string $column): static |
|
| 87 | + public function setPrimaryKey(array | string $column): static |
|
| 88 | 88 | { |
| 89 | 89 | if (!is_array($column)) { |
| 90 | - $column = [ $column ]; |
|
| 90 | + $column = [$column]; |
|
| 91 | 91 | } |
| 92 | 92 | $this->data['primary'] = array_values($column); |
| 93 | 93 | return $this; |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function getFullName(): string |
| 116 | 116 | { |
| 117 | - return ($this->data['schema'] ? $this->data['schema'] . '.' : '') . $this->data['name']; |
|
| 117 | + return ($this->data['schema'] ? $this->data['schema'].'.' : '').$this->data['name']; |
|
| 118 | 118 | } |
| 119 | 119 | /** |
| 120 | 120 | * Get a column definition |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | public function hasOne( |
| 172 | 172 | Table $toTable, |
| 173 | 173 | ?string $name = null, |
| 174 | - string|array|null $toTableColumn = null, |
|
| 174 | + string | array | null $toTableColumn = null, |
|
| 175 | 175 | ?string $sql = null, |
| 176 | 176 | array $par = [] |
| 177 | 177 | ) : static { |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | if (!isset($name)) { |
| 202 | - $name = $toTable->getName() . '_' . implode('_', array_keys($keymap)); |
|
| 202 | + $name = $toTable->getName().'_'.implode('_', array_keys($keymap)); |
|
| 203 | 203 | } |
| 204 | 204 | $this->addRelation(new TableRelation( |
| 205 | 205 | $this, |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | public function hasMany( |
| 227 | 227 | Table $toTable, |
| 228 | 228 | ?string $name = null, |
| 229 | - string|array|null $toTableColumn = null, |
|
| 229 | + string | array | null $toTableColumn = null, |
|
| 230 | 230 | ?string $sql = null, |
| 231 | 231 | array $par = [] |
| 232 | 232 | ): static { |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | public function belongsTo( |
| 282 | 282 | Table $toTable, |
| 283 | 283 | ?string $name = null, |
| 284 | - string|array|null $localColumn = null, |
|
| 284 | + string | array | null $localColumn = null, |
|
| 285 | 285 | ?string $sql = null, |
| 286 | 286 | array $par = [] |
| 287 | 287 | ): static { |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | Table $toTable, |
| 338 | 338 | Table $pivot, |
| 339 | 339 | ?string $name = null, |
| 340 | - string|array|null $toTableColumn = null, |
|
| 341 | - string|array|null $localColumn = null |
|
| 340 | + string | array | null $toTableColumn = null, |
|
| 341 | + string | array | null $localColumn = null |
|
| 342 | 342 | ): static { |
| 343 | 343 | $pivotColumns = $pivot->getColumns(); |
| 344 | 344 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function __construct( |
| 21 | 21 | DBInterface $db, |
| 22 | - Table|string $table, |
|
| 22 | + Table | string $table, |
|
| 23 | 23 | bool $findRelations = false, |
| 24 | 24 | ?MapperInterface $mapper = null |
| 25 | 25 | ) { |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | public function iterator(?array $fields = null, ?array $collectionKey = null): Collection |
| 35 | 35 | { |
| 36 | 36 | return Collection::from(parent::iterator($fields, $collectionKey)) |
| 37 | - ->map(function ($v) { |
|
| 37 | + ->map(function($v) { |
|
| 38 | 38 | return $this->mapper->entity($v); |
| 39 | 39 | }) |
| 40 | 40 | ->values(); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | if (isset($this->map)) { |
| 27 | 27 | $par = []; |
| 28 | 28 | foreach ($this->map as $key) { |
| 29 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 29 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 30 | 30 | } |
| 31 | 31 | $data = $par; |
| 32 | 32 | } |
@@ -34,28 +34,28 @@ discard block |
||
| 34 | 34 | foreach ($data as $i => $v) { |
| 35 | 35 | switch (gettype($v)) { |
| 36 | 36 | case 'boolean': |
| 37 | - $this->statement->bindValue($i+1, $v, \PDO::PARAM_BOOL); |
|
| 37 | + $this->statement->bindValue($i + 1, $v, \PDO::PARAM_BOOL); |
|
| 38 | 38 | break; |
| 39 | 39 | case 'integer': |
| 40 | - $this->statement->bindValue($i+1, $v, \PDO::PARAM_INT); |
|
| 40 | + $this->statement->bindValue($i + 1, $v, \PDO::PARAM_INT); |
|
| 41 | 41 | break; |
| 42 | 42 | case 'NULL': |
| 43 | - $this->statement->bindValue($i+1, $v, \PDO::PARAM_NULL); |
|
| 43 | + $this->statement->bindValue($i + 1, $v, \PDO::PARAM_NULL); |
|
| 44 | 44 | break; |
| 45 | 45 | case 'double': |
| 46 | - $this->statement->bindValue($i+1, $v); |
|
| 46 | + $this->statement->bindValue($i + 1, $v); |
|
| 47 | 47 | break; |
| 48 | 48 | default: |
| 49 | 49 | // keep in mind oracle needs a transaction when inserting LOBs, aside from the specific syntax: |
| 50 | 50 | // INSERT INTO table (column, lobcolumn) VALUES (?, ?, EMPTY_BLOB()) RETURNING lobcolumn INTO ? |
| 51 | 51 | if (is_resource($v) && get_resource_type($v) === 'stream') { |
| 52 | - $this->statement->bindParam($i+1, $v, \PDO::PARAM_LOB); |
|
| 52 | + $this->statement->bindParam($i + 1, $v, \PDO::PARAM_LOB); |
|
| 53 | 53 | break; |
| 54 | 54 | } |
| 55 | 55 | if (!is_string($data[$i])) { |
| 56 | 56 | $data[$i] = serialize($data[$i]); |
| 57 | 57 | } |
| 58 | - $this->statement->bindValue($i+1, $v); |
|
| 58 | + $this->statement->bindValue($i + 1, $v); |
|
| 59 | 59 | break; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | if (isset($this->map)) { |
| 29 | 29 | $par = []; |
| 30 | 30 | foreach ($this->map as $key) { |
| 31 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 31 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 32 | 32 | } |
| 33 | 33 | $data = $par; |
| 34 | 34 | } |
@@ -49,23 +49,23 @@ discard block |
||
| 49 | 49 | break; |
| 50 | 50 | case 'array': |
| 51 | 51 | $par = implode(',', $par); |
| 52 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 52 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 53 | 53 | break; |
| 54 | 54 | case 'object': |
| 55 | 55 | $par = serialize($par); |
| 56 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 56 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 57 | 57 | break; |
| 58 | 58 | case 'resource': |
| 59 | 59 | if (is_resource($par) && get_resource_type($par) === 'stream') { |
| 60 | 60 | $par = stream_get_contents($par); |
| 61 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 61 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 62 | 62 | } else { |
| 63 | 63 | $par = serialize($par); |
| 64 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 64 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 65 | 65 | } |
| 66 | 66 | break; |
| 67 | 67 | default: |
| 68 | - $par = "'" . $this->lnk->escape_string((string)$par) . "'"; |
|
| 68 | + $par = "'".$this->lnk->escape_string((string) $par)."'"; |
|
| 69 | 69 | break; |
| 70 | 70 | } |
| 71 | 71 | $sql .= $par; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | if (isset($this->map)) { |
| 32 | 32 | $par = []; |
| 33 | 33 | foreach ($this->map as $key) { |
| 34 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 34 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 35 | 35 | } |
| 36 | 36 | $data = $par; |
| 37 | 37 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | foreach ($lng as $index) { |
| 87 | 87 | if (is_resource($data[$index]) && get_resource_type($data[$index]) === 'stream') { |
| 88 | 88 | while (!feof($data[$index])) { |
| 89 | - $this->statement->send_long_data($index, (string)fread($data[$index], $lds)); |
|
| 89 | + $this->statement->send_long_data($index, (string) fread($data[$index], $lds)); |
|
| 90 | 90 | } |
| 91 | 91 | } else { |
| 92 | 92 | $data[$index] = str_split($data[$index], $lds); |
@@ -106,24 +106,24 @@ discard block |
||
| 106 | 106 | $res = false; |
| 107 | 107 | } |
| 108 | 108 | if (!$res) { |
| 109 | - if ($log && (int)$this->driver->option('log_errors', 1)) { |
|
| 109 | + if ($log && (int) $this->driver->option('log_errors', 1)) { |
|
| 110 | 110 | @file_put_contents( |
| 111 | 111 | $log, |
| 112 | - '--' . date('Y-m-d H:i:s') . ' ERROR: ' . $this->statement->error . "\r\n" . |
|
| 113 | - $this->sql . "\r\n" . |
|
| 112 | + '--'.date('Y-m-d H:i:s').' ERROR: '.$this->statement->error."\r\n". |
|
| 113 | + $this->sql."\r\n". |
|
| 114 | 114 | "\r\n", |
| 115 | 115 | FILE_APPEND |
| 116 | 116 | ); |
| 117 | 117 | } |
| 118 | - throw new DBException('Prepared execute error: ' . $this->statement->error); |
|
| 118 | + throw new DBException('Prepared execute error: '.$this->statement->error); |
|
| 119 | 119 | } |
| 120 | 120 | if ($log) { |
| 121 | 121 | $tm = microtime(true) - $tm; |
| 122 | - if ($tm >= (float)$this->driver->option('log_slow', 0)) { |
|
| 122 | + if ($tm >= (float) $this->driver->option('log_slow', 0)) { |
|
| 123 | 123 | @file_put_contents( |
| 124 | 124 | $log, |
| 125 | - '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" . |
|
| 126 | - $this->sql . "\r\n" . |
|
| 125 | + '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n". |
|
| 126 | + $this->sql."\r\n". |
|
| 127 | 127 | "\r\n", |
| 128 | 128 | FILE_APPEND |
| 129 | 129 | ); |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | if (isset($this->map)) { |
| 37 | 37 | $par = []; |
| 38 | 38 | foreach ($this->map as $key) { |
| 39 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 39 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 40 | 40 | } |
| 41 | 41 | $data = $par; |
| 42 | 42 | } |
@@ -25,17 +25,17 @@ discard block |
||
| 25 | 25 | if (strpos(strtolower($statement), 'prepare') === 0) { |
| 26 | 26 | $this->drv->raw($this->statement); |
| 27 | 27 | if (!isset($this->name)) { |
| 28 | - $this->name = trim((preg_split('(\s+)', trim($this->statement))?:[])[1]??'', '"'); |
|
| 28 | + $this->name = trim((preg_split('(\s+)', trim($this->statement)) ?: [])[1] ?? '', '"'); |
|
| 29 | 29 | } |
| 30 | 30 | } elseif ($this->name !== null) { |
| 31 | 31 | $temp = \pg_prepare($this->driver, $this->name, $this->statement); |
| 32 | 32 | if (!$temp) { |
| 33 | 33 | $log = $this->drv->option('log_file'); |
| 34 | - if ($log && (int)$this->drv->option('log_errors', 1)) { |
|
| 34 | + if ($log && (int) $this->drv->option('log_errors', 1)) { |
|
| 35 | 35 | @file_put_contents( |
| 36 | 36 | $log, |
| 37 | - '--' . date('Y-m-d H:i:s') . ' ERROR PREPARING: ' . \pg_last_error($this->driver) . "\r\n" . |
|
| 38 | - $this->statement . "\r\n" . |
|
| 37 | + '--'.date('Y-m-d H:i:s').' ERROR PREPARING: '.\pg_last_error($this->driver)."\r\n". |
|
| 38 | + $this->statement."\r\n". |
|
| 39 | 39 | "\r\n", |
| 40 | 40 | FILE_APPEND |
| 41 | 41 | ); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | if (isset($this->map)) { |
| 58 | 58 | $par = []; |
| 59 | 59 | foreach ($this->map as $key) { |
| 60 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 60 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 61 | 61 | } |
| 62 | 62 | $data = $par; |
| 63 | 63 | } |
@@ -68,22 +68,20 @@ discard block |
||
| 68 | 68 | try { |
| 69 | 69 | if ($this->name !== null) { |
| 70 | 70 | $temp = (count($data)) ? |
| 71 | - \pg_execute($this->driver, $this->name, $data) : |
|
| 72 | - \pg_execute($this->driver, $this->name, array()); |
|
| 71 | + \pg_execute($this->driver, $this->name, $data) : \pg_execute($this->driver, $this->name, array()); |
|
| 73 | 72 | } else { |
| 74 | 73 | $temp = (count($data)) ? |
| 75 | - \pg_query_params($this->driver, $this->statement, $data) : |
|
| 76 | - \pg_query_params($this->driver, $this->statement, array()); |
|
| 74 | + \pg_query_params($this->driver, $this->statement, $data) : \pg_query_params($this->driver, $this->statement, array()); |
|
| 77 | 75 | } |
| 78 | 76 | } catch (\Exception $e) { |
| 79 | 77 | $temp = false; |
| 80 | 78 | } |
| 81 | 79 | if (!$temp) { |
| 82 | - if ($log && (int)$this->drv->option('log_errors', 1)) { |
|
| 80 | + if ($log && (int) $this->drv->option('log_errors', 1)) { |
|
| 83 | 81 | @file_put_contents( |
| 84 | 82 | $log, |
| 85 | - '--' . date('Y-m-d H:i:s') . ' ERROR: ' . \pg_last_error($this->driver) . "\r\n" . |
|
| 86 | - $this->statement . "\r\n" . |
|
| 83 | + '--'.date('Y-m-d H:i:s').' ERROR: '.\pg_last_error($this->driver)."\r\n". |
|
| 84 | + $this->statement."\r\n". |
|
| 87 | 85 | "\r\n", |
| 88 | 86 | FILE_APPEND |
| 89 | 87 | ); |
@@ -92,11 +90,11 @@ discard block |
||
| 92 | 90 | } |
| 93 | 91 | if ($log) { |
| 94 | 92 | $tm = microtime(true) - $tm; |
| 95 | - if ($tm >= (float)$this->drv->option('log_slow', 0)) { |
|
| 93 | + if ($tm >= (float) $this->drv->option('log_slow', 0)) { |
|
| 96 | 94 | @file_put_contents( |
| 97 | 95 | $log, |
| 98 | - '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" . |
|
| 99 | - $this->statement . "\r\n" . |
|
| 96 | + '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n". |
|
| 97 | + $this->statement."\r\n". |
|
| 100 | 98 | "\r\n", |
| 101 | 99 | FILE_APPEND |
| 102 | 100 | ); |