@@ -71,7 +71,7 @@ |
||
71 | 71 | $this->softDetect($sql); |
72 | 72 | $statement = \ibase_prepare($this->transaction !== null ? $this->transaction : $this->lnk, $sql); |
73 | 73 | if ($statement === false) { |
74 | - throw new DBException('Prepare error: ' . \ibase_errmsg()); |
|
74 | + throw new DBException('Prepare error: '.\ibase_errmsg()); |
|
75 | 75 | } |
76 | 76 | return new Statement( |
77 | 77 | $statement, |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $this->query("ALTER SESSION SET time_zone = '".addslashes($timezone)."'"); |
45 | 45 | } |
46 | 46 | if ($schema = $this->option('schema')) { |
47 | - $this->query("ALTER SESSION SET CURRENT_SCHEMA = " . $schema); |
|
47 | + $this->query("ALTER SESSION SET CURRENT_SCHEMA = ".$schema); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | } |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | ); |
82 | 82 | if ($log) { |
83 | 83 | $tm = microtime(true) - $tm; |
84 | - if ($tm >= (float)$this->option('log_slow', 0)) { |
|
84 | + if ($tm >= (float) $this->option('log_slow', 0)) { |
|
85 | 85 | @file_put_contents( |
86 | 86 | $log, |
87 | - '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" . |
|
88 | - $sql . "\r\n" . |
|
87 | + '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n". |
|
88 | + $sql."\r\n". |
|
89 | 89 | "\r\n", |
90 | 90 | FILE_APPEND |
91 | 91 | ); |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | if (isset($this->connection['opts']['search_path'])) { |
46 | 46 | @\pg_query( |
47 | 47 | $this->lnk, |
48 | - "SET search_path TO " . pg_escape_string($this->connection['opts']['search_path']) |
|
48 | + "SET search_path TO ".pg_escape_string($this->connection['opts']['search_path']) |
|
49 | 49 | ); |
50 | 50 | } |
51 | 51 | if (!isset($this->connection['opts']['search_path']) && isset($this->connection['opts']['schema'])) { |
52 | - @\pg_query($this->lnk, "SET search_path TO " . pg_escape_string($this->connection['opts']['schema'])); |
|
52 | + @\pg_query($this->lnk, "SET search_path TO ".pg_escape_string($this->connection['opts']['schema'])); |
|
53 | 53 | } |
54 | 54 | if (isset($this->connection['opts']['timezone'])) { |
55 | 55 | @\pg_query($this->lnk, "SET TIME ZONE '".pg_escape_string($this->connection['opts']['timezone'])."'"); |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | $res = \pg_query($this->lnk, $sql); |
88 | 88 | if ($log) { |
89 | 89 | $tm = microtime(true) - $tm; |
90 | - if ($tm >= (float)$this->option('log_slow', 0)) { |
|
90 | + if ($tm >= (float) $this->option('log_slow', 0)) { |
|
91 | 91 | @file_put_contents( |
92 | 92 | $log, |
93 | - '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" . |
|
94 | - $sql . "\r\n" . |
|
93 | + '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n". |
|
94 | + $sql."\r\n". |
|
95 | 95 | "\r\n", |
96 | 96 | FILE_APPEND |
97 | 97 | ); |
@@ -37,8 +37,7 @@ discard block |
||
37 | 37 | $temp = @\pg_query( |
38 | 38 | $this->driver, |
39 | 39 | $sequence ? |
40 | - 'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' : |
|
41 | - 'SELECT lastval()' |
|
40 | + 'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' : 'SELECT lastval()' |
|
42 | 41 | ); |
43 | 42 | if ($temp) { |
44 | 43 | $res = \pg_fetch_row($temp); |
@@ -76,8 +75,8 @@ discard block |
||
76 | 75 | } |
77 | 76 | public function next(): void |
78 | 77 | { |
79 | - $this->fetched ++; |
|
80 | - $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC)?:null; |
|
78 | + $this->fetched++; |
|
79 | + $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC) ?: null; |
|
81 | 80 | if (is_array($this->last)) { |
82 | 81 | $this->cast(); |
83 | 82 | } |
@@ -90,11 +89,11 @@ discard block |
||
90 | 89 | protected function cast(): void |
91 | 90 | { |
92 | 91 | if (!count($this->types)) { |
93 | - foreach (array_keys($this->last??[]) as $k => $v) { |
|
92 | + foreach (array_keys($this->last ?? []) as $k => $v) { |
|
94 | 93 | $this->types[$v] = \pg_field_type($this->statement, $k); |
95 | 94 | } |
96 | 95 | } |
97 | - foreach ($this->last??[] as $k => $v) { |
|
96 | + foreach ($this->last ?? [] as $k => $v) { |
|
98 | 97 | if (is_null($v) || !isset($this->types[$k])) { |
99 | 98 | continue; |
100 | 99 | } |
@@ -102,15 +101,15 @@ discard block |
||
102 | 101 | case 'int2': |
103 | 102 | case 'int4': |
104 | 103 | case 'int8': |
105 | - $this->last[$k] = (int)$v; |
|
104 | + $this->last[$k] = (int) $v; |
|
106 | 105 | break; |
107 | 106 | case 'bit': |
108 | 107 | case 'bool': |
109 | - $this->last[$k] = $v !== 'f' && (int)$v ? true : false; |
|
108 | + $this->last[$k] = $v !== 'f' && (int) $v ? true : false; |
|
110 | 109 | break; |
111 | 110 | case 'float4': |
112 | 111 | case 'float8': |
113 | - $this->last[$k] = (float)$v; |
|
112 | + $this->last[$k] = (float) $v; |
|
114 | 113 | break; |
115 | 114 | case 'money': |
116 | 115 | case 'numeric': |
@@ -38,7 +38,7 @@ |
||
38 | 38 | if ($this->lnk === null) { |
39 | 39 | try { |
40 | 40 | $this->lnk = new \SQLite3($this->connection['name']); |
41 | - $this->lnk->exec('PRAGMA encoding = "'.$this->option('charset', 'utf-8') . '"'); |
|
41 | + $this->lnk->exec('PRAGMA encoding = "'.$this->option('charset', 'utf-8').'"'); |
|
42 | 42 | } catch (\Exception $e) { |
43 | 43 | if ($this->lnk !== null) { |
44 | 44 | throw new DBException('Connect error: '.$this->lnk->lastErrorMsg()); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $instance->setNullable($data['nullable']); |
43 | 43 | } |
44 | 44 | if (isset($data['notnull'])) { |
45 | - $instance->setNullable(!((int)$data['notnull'])); |
|
45 | + $instance->setNullable(!((int) $data['notnull'])); |
|
46 | 46 | } |
47 | 47 | if (isset($data['Default'])) { |
48 | 48 | $instance->setDefault($data['Default']); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $instance->setLength($data['length']); |
58 | 58 | } |
59 | 59 | if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) { |
60 | - $temp = array_map(function ($v) { |
|
60 | + $temp = array_map(function($v) { |
|
61 | 61 | return str_replace("''", "'", $v); |
62 | 62 | }, explode("','", substr($instance->getType(), 6, -2))); |
63 | 63 | $instance->setValues($temp); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $instance->setDefault(null); |
87 | 87 | } |
88 | 88 | } |
89 | - if ($instance->getBasicType() === 'text' && isset($data['CHAR_LENGTH']) && (int)$data['CHAR_LENGTH']) { |
|
89 | + if ($instance->getBasicType() === 'text' && isset($data['CHAR_LENGTH']) && (int) $data['CHAR_LENGTH']) { |
|
90 | 90 | $instance->setLength($data['CHAR_LENGTH']); |
91 | 91 | } |
92 | 92 | return $instance; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | } |
184 | 184 | public function getLength(): int |
185 | 185 | { |
186 | - return (int)$this->length; |
|
186 | + return (int) $this->length; |
|
187 | 187 | } |
188 | 188 | public function setLength(int $length): static |
189 | 189 | { |
@@ -58,12 +58,12 @@ |
||
58 | 58 | * @param array|T $entity |
59 | 59 | * @return bool |
60 | 60 | */ |
61 | - public function deleted(array|object $entity): bool; |
|
61 | + public function deleted(array | object $entity): bool; |
|
62 | 62 | /** |
63 | 63 | * @param array|T $entity |
64 | 64 | * @return bool |
65 | 65 | */ |
66 | - public function exists(array|object $entity): bool; |
|
66 | + public function exists(array | object $entity): bool; |
|
67 | 67 | /** |
68 | 68 | * @return array<int,T> |
69 | 69 | */ |
@@ -539,7 +539,7 @@ |
||
539 | 539 | (isset($value) && is_array($value) && !in_array($e, $value, true)) || |
540 | 540 | (($value instanceof Collection) && !$value->contains($e)) |
541 | 541 | ) |
542 | - ) { |
|
542 | + ) { |
|
543 | 543 | $mapper->delete($e, true); |
544 | 544 | } |
545 | 545 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @param class-string<T> $clss |
28 | 28 | * @return void |
29 | 29 | */ |
30 | - public function __construct(DBInterface $db, string|Table|null $table = '', string $clss = Entity::class) |
|
30 | + public function __construct(DBInterface $db, string | Table | null $table = '', string $clss = Entity::class) |
|
31 | 31 | { |
32 | 32 | $this->db = $db; |
33 | 33 | if (!$table) { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $temp = []; |
64 | 64 | foreach ($this->table->getPrimaryKey() as $column) { |
65 | 65 | try { |
66 | - $temp[(string)$column] = $entity->{$column} ?? null; |
|
66 | + $temp[(string) $column] = $entity->{$column} ?? null; |
|
67 | 67 | /** @phpstan-ignore-next-line */ |
68 | 68 | } catch (\Throwable $ignore) { |
69 | 69 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | // BEG: ugly hack to get relations changed directly on the object (not hydrated) |
95 | 95 | $hack = []; |
96 | - foreach ((array)$entity as $k => $v) { |
|
96 | + foreach ((array) $entity as $k => $v) { |
|
97 | 97 | $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v; |
98 | 98 | } |
99 | 99 | $hack = $hack['changed'] ?? []; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | foreach ($columns as $column) { |
105 | 105 | try { |
106 | 106 | if (in_array($column, $fetched) || array_key_exists($column, $hack) || $fetch) { |
107 | - $temp[(string)$column] = $entity->{$column}; |
|
107 | + $temp[(string) $column] = $entity->{$column}; |
|
108 | 108 | } |
109 | 109 | } catch (\Throwable $ignore) { |
110 | 110 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | foreach ($relations as $relation) { |
115 | 115 | try { |
116 | 116 | if (array_key_exists($relation, $fetched) || array_key_exists($relation, $hack) || $fetch) { |
117 | - $temp[(string)$relation] = $entity->{$relation}; |
|
117 | + $temp[(string) $relation] = $entity->{$relation}; |
|
118 | 118 | } |
119 | 119 | } catch (\Throwable $ignore) { |
120 | 120 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $v = []; |
136 | 136 | } |
137 | 137 | if ($v instanceof Entity) { |
138 | - $v = [ $v ]; |
|
138 | + $v = [$v]; |
|
139 | 139 | } |
140 | 140 | if (is_array($v)) { |
141 | 141 | foreach ($v as $kk => $vv) { |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | $temp = []; |
185 | 185 | foreach ($this->table->getColumns() as $column) { |
186 | 186 | if (array_key_exists($column, $data)) { |
187 | - $temp[(string)$column] = $data[$column]; |
|
187 | + $temp[(string) $column] = $data[$column]; |
|
188 | 188 | } else { |
189 | 189 | if ($empty) { |
190 | - $temp[(string)$column] = null; |
|
190 | + $temp[(string) $column] = null; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $lazy = []; |
216 | 216 | foreach ($this->table->getColumns() as $column) { |
217 | 217 | if (!array_key_exists($column, $data)) { |
218 | - $lazy[$column] = function ($entity) use ($column) { |
|
218 | + $lazy[$column] = function($entity) use ($column) { |
|
219 | 219 | $query = $this->db->table($this->table->getFullName()); |
220 | 220 | foreach ($this->id($entity) as $k => $v) { |
221 | 221 | $query->filter($k, $v); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | { |
239 | 239 | $relations = []; |
240 | 240 | foreach ($this->table->getRelations() as $name => $relation) { |
241 | - $relations[$name] = function ( |
|
241 | + $relations[$name] = function( |
|
242 | 242 | $entity, |
243 | 243 | bool $queryOnly = false |
244 | 244 | ) use ( |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | return $this->objects[spl_object_hash($entity)][4][$name] = null; |
253 | 253 | } |
254 | 254 | $value = $relation->many ? |
255 | - Collection::from(array_map(function ($v) use ($mapper) { |
|
255 | + Collection::from(array_map(function($v) use ($mapper) { |
|
256 | 256 | return $mapper->entity($v); |
257 | 257 | }, $data[$name])) |
258 | - ->filter(function ($v) use ($mapper) { |
|
258 | + ->filter(function($v) use ($mapper) { |
|
259 | 259 | return !$mapper->deleted($v); |
260 | 260 | }) : |
261 | 261 | ($mapper->deleted($data[$name]) ? null : $mapper->entity($data[$name])); |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | } |
265 | 265 | $query = $this->db->tableMapped($relation->table->getFullName()); |
266 | 266 | if ($relation->sql) { |
267 | - $query->where($relation->sql, $relation->par?:[]); |
|
267 | + $query->where($relation->sql, $relation->par ?: []); |
|
268 | 268 | } |
269 | 269 | if ($relation->pivot) { |
270 | 270 | $nm = null; |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | } |
286 | 286 | $pk = $this->id($entity); |
287 | 287 | foreach ($pk as $k => $v) { |
288 | - $query->filter($nm . '.' . $k, $v); |
|
288 | + $query->filter($nm.'.'.$k, $v); |
|
289 | 289 | } |
290 | 290 | } else { |
291 | 291 | $temp = $this->toArray($entity, array_keys($relation->keymap)); |
@@ -297,10 +297,9 @@ discard block |
||
297 | 297 | return $query; |
298 | 298 | } |
299 | 299 | $value = $relation->many ? |
300 | - $query->iterator() : |
|
301 | - ($query[0] ?? null); |
|
300 | + $query->iterator() : ($query[0] ?? null); |
|
302 | 301 | if ($value instanceof Collection) { |
303 | - $value->filter(function ($v) use ($mapper) { |
|
302 | + $value->filter(function($v) use ($mapper) { |
|
304 | 303 | return !$mapper->deleted($v); |
305 | 304 | }); |
306 | 305 | } elseif (isset($value) && $mapper->deleted($value)) { |
@@ -320,7 +319,7 @@ discard block |
||
320 | 319 | { |
321 | 320 | // BEG: ugly hack to get changed columns |
322 | 321 | $hack = []; |
323 | - foreach ((array)$entity as $k => $v) { |
|
322 | + foreach ((array) $entity as $k => $v) { |
|
324 | 323 | $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v; |
325 | 324 | } |
326 | 325 | $hack = $hack['changed'] ?? []; |
@@ -611,7 +610,7 @@ discard block |
||
611 | 610 | } |
612 | 611 | } |
613 | 612 | } |
614 | - public function exists(array|object $entity): bool |
|
613 | + public function exists(array | object $entity): bool |
|
615 | 614 | { |
616 | 615 | if (is_array($entity)) { |
617 | 616 | $primary = []; |
@@ -625,7 +624,7 @@ discard block |
||
625 | 624 | return isset($this->objects[spl_object_hash($entity)]) && |
626 | 625 | $this->objects[spl_object_hash($entity)][5] === false; |
627 | 626 | } |
628 | - public function deleted(array|object $entity): bool |
|
627 | + public function deleted(array | object $entity): bool |
|
629 | 628 | { |
630 | 629 | if (is_array($entity)) { |
631 | 630 | $primary = []; |
@@ -711,7 +710,7 @@ discard block |
||
711 | 710 | return array_filter( |
712 | 711 | array_values( |
713 | 712 | array_map( |
714 | - function ($v) { |
|
713 | + function($v) { |
|
715 | 714 | return $v[5] ? null : ($v[1] ?? null); |
716 | 715 | }, |
717 | 716 | $this->objects |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | public function getTable(string $table): Table |
32 | 32 | { |
33 | 33 | if (!$this->hasTable($table)) { |
34 | - throw new DBException('Invalid table name: ' . $table); |
|
34 | + throw new DBException('Invalid table name: '.$table); |
|
35 | 35 | } |
36 | 36 | return $this->tables[$table] ?? |
37 | 37 | $this->tables[strtoupper($table)] ?? |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | |
65 | 65 | public function toArray(): array |
66 | 66 | { |
67 | - return array_map(function ($table) { |
|
67 | + return array_map(function($table) { |
|
68 | 68 | return [ |
69 | 69 | 'name' => $table->getName(), |
70 | 70 | 'schema' => $table->getSchema(), |
71 | 71 | 'pkey' => $table->getPrimaryKey(), |
72 | 72 | 'comment' => $table->getComment(), |
73 | - 'columns' => array_map(function ($column) { |
|
73 | + 'columns' => array_map(function($column) { |
|
74 | 74 | return [ |
75 | 75 | 'name' => $column->getName(), |
76 | 76 | 'type' => $column->getType(), |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | 'nullable' => $column->isNullable() |
82 | 82 | ]; |
83 | 83 | }, $table->getFullColumns()), |
84 | - 'relations' => array_map(function ($rel) { |
|
84 | + 'relations' => array_map(function($rel) { |
|
85 | 85 | $relation = clone $rel; |
86 | - $relation = (array)$relation; |
|
86 | + $relation = (array) $relation; |
|
87 | 87 | $relation['table'] = $rel->table->getName(); |
88 | 88 | if ($rel->pivot) { |
89 | 89 | $relation['pivot'] = $rel->pivot->getName(); |