@@ -40,23 +40,23 @@ |
||
40 | 40 | break; |
41 | 41 | case 'array': |
42 | 42 | $par = implode(',', $par); |
43 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
43 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
44 | 44 | break; |
45 | 45 | case 'object': |
46 | 46 | $par = serialize($par); |
47 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
47 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
48 | 48 | break; |
49 | 49 | case 'resource': |
50 | 50 | if (is_resource($par) && get_resource_type($par) === 'stream') { |
51 | 51 | $par = stream_get_contents($par); |
52 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
52 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
53 | 53 | } else { |
54 | 54 | $par = serialize($par); |
55 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
55 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
56 | 56 | } |
57 | 57 | break; |
58 | 58 | default: |
59 | - $par = "'" . $this->lnk->escape_string((string)$par) . "'"; |
|
59 | + $par = "'".$this->lnk->escape_string((string) $par)."'"; |
|
60 | 60 | break; |
61 | 61 | } |
62 | 62 | $sql .= $par; |
@@ -78,7 +78,7 @@ |
||
78 | 78 | } |
79 | 79 | public function next(): void |
80 | 80 | { |
81 | - $this->fetched ++; |
|
81 | + $this->fetched++; |
|
82 | 82 | $temp = \odbc_fetch_row($this->statement); |
83 | 83 | if (!$temp) { |
84 | 84 | $this->last = null; |
@@ -62,8 +62,8 @@ |
||
62 | 62 | } |
63 | 63 | public function next(): void |
64 | 64 | { |
65 | - $this->fetched ++; |
|
66 | - $this->last = $this->statement->fetchArray(\SQLITE3_ASSOC)?:null; |
|
65 | + $this->fetched++; |
|
66 | + $this->last = $this->statement->fetchArray(\SQLITE3_ASSOC) ?: null; |
|
67 | 67 | } |
68 | 68 | public function valid(): bool |
69 | 69 | { |
@@ -67,8 +67,8 @@ |
||
67 | 67 | } |
68 | 68 | public function next(): void |
69 | 69 | { |
70 | - $this->fetched ++; |
|
71 | - $this->last = \ibase_fetch_assoc($this->result, \IBASE_TEXT)?:null; |
|
70 | + $this->fetched++; |
|
71 | + $this->last = \ibase_fetch_assoc($this->result, \IBASE_TEXT) ?: null; |
|
72 | 72 | } |
73 | 73 | public function valid(): bool |
74 | 74 | { |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | * @param array|string $column either a single column name or an array of column names |
80 | 80 | * @return static |
81 | 81 | */ |
82 | - public function setPrimaryKey(array|string $column): static |
|
82 | + public function setPrimaryKey(array | string $column): static |
|
83 | 83 | { |
84 | 84 | if (!is_array($column)) { |
85 | - $column = [ $column ]; |
|
85 | + $column = [$column]; |
|
86 | 86 | } |
87 | 87 | $this->data['primary'] = array_values($column); |
88 | 88 | return $this; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function getFullName(): string |
111 | 111 | { |
112 | - return ($this->data['schema'] ? $this->data['schema'] . '.' : '') . $this->data['name']; |
|
112 | + return ($this->data['schema'] ? $this->data['schema'].'.' : '').$this->data['name']; |
|
113 | 113 | } |
114 | 114 | /** |
115 | 115 | * Get a column definition |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | public function hasOne( |
157 | 157 | Table $toTable, |
158 | 158 | string $name = null, |
159 | - string|array|null $toTableColumn = null, |
|
159 | + string | array | null $toTableColumn = null, |
|
160 | 160 | string $sql = null, |
161 | 161 | array $par = [] |
162 | 162 | ) : static { |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | if (!isset($name)) { |
187 | - $name = $toTable->getName() . '_' . implode('_', array_keys($keymap)); |
|
187 | + $name = $toTable->getName().'_'.implode('_', array_keys($keymap)); |
|
188 | 188 | } |
189 | 189 | $this->addRelation(new TableRelation( |
190 | 190 | $name, |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | public function hasMany( |
211 | 211 | Table $toTable, |
212 | 212 | string $name = null, |
213 | - string|array|null $toTableColumn = null, |
|
213 | + string | array | null $toTableColumn = null, |
|
214 | 214 | ?string $sql = null, |
215 | 215 | array $par = [] |
216 | 216 | ): static { |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | public function belongsTo( |
265 | 265 | Table $toTable, |
266 | 266 | string $name = null, |
267 | - string|array|null $localColumn = null, |
|
267 | + string | array | null $localColumn = null, |
|
268 | 268 | ?string $sql = null, |
269 | 269 | array $par = [] |
270 | 270 | ): static { |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | Table $toTable, |
320 | 320 | Table $pivot, |
321 | 321 | ?string $name = null, |
322 | - string|array|null $toTableColumn = null, |
|
323 | - string|array|null $localColumn = null |
|
322 | + string | array | null $toTableColumn = null, |
|
323 | + string | array | null $localColumn = null |
|
324 | 324 | ): static { |
325 | 325 | $pivotColumns = $pivot->getColumns(); |
326 | 326 |
@@ -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 | ); |
@@ -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 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | $table = $temp[1]; |
30 | 30 | } |
31 | 31 | |
32 | - if (isset($tables[$schema . '.' . $table])) { |
|
33 | - return $tables[$schema . '.' . $table]; |
|
32 | + if (isset($tables[$schema.'.'.$table])) { |
|
33 | + return $tables[$schema.'.'.$table]; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | static $relationsT = null; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | (kc.table_schema = ? OR ct.table_schema = ?) AND |
62 | 62 | kc.table_name IS NOT NULL AND |
63 | 63 | kc.position_in_unique_constraint IS NOT NULL", |
64 | - [ $catalog, $main, $main ] |
|
64 | + [$catalog, $main, $main] |
|
65 | 65 | ) |
66 | 66 | )->toArray(); |
67 | 67 | foreach ($col as $row) { |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | if ($row['referenced_table_schema'] !== $main) { |
72 | 72 | $additional[] = $row['referenced_table_schema']; |
73 | 73 | } |
74 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
75 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
74 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
75 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
76 | 76 | } |
77 | 77 | foreach (array_filter(array_unique($additional)) as $s) { |
78 | 78 | $col = Collection::from( |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | (kc.table_schema = ? AND ct.table_schema = ?) AND |
98 | 98 | kc.table_name IS NOT NULL AND |
99 | 99 | kc.position_in_unique_constraint IS NOT NULL", |
100 | - [ $catalog, $s, $s ] |
|
100 | + [$catalog, $s, $s] |
|
101 | 101 | ) |
102 | 102 | )->toArray(); |
103 | 103 | foreach ($col as $row) { |
104 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
105 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
104 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
105 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | ->query( |
112 | 112 | "SELECT * FROM information_schema.columns |
113 | 113 | WHERE table_name = ? AND table_schema = ? AND table_catalog = ?", |
114 | - [ $table, $schema, $catalog ] |
|
114 | + [$table, $schema, $catalog] |
|
115 | 115 | )) |
116 | - ->mapKey(function ($v) { |
|
116 | + ->mapKey(function($v) { |
|
117 | 117 | return $v['column_name']; |
118 | 118 | }) |
119 | - ->map(function ($v) { |
|
119 | + ->map(function($v) { |
|
120 | 120 | $v['length'] = null; |
121 | 121 | if (!isset($v['data_type'])) { |
122 | 122 | return $v; |
@@ -124,20 +124,20 @@ discard block |
||
124 | 124 | switch ($v['data_type']) { |
125 | 125 | case 'character': |
126 | 126 | case 'character varying': |
127 | - $v['length'] = (int)$v['character_maximum_length']; |
|
127 | + $v['length'] = (int) $v['character_maximum_length']; |
|
128 | 128 | break; |
129 | 129 | } |
130 | 130 | return $v; |
131 | 131 | }) |
132 | 132 | ->toArray(); |
133 | 133 | if (!count($columns)) { |
134 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
134 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
135 | 135 | } |
136 | 136 | $pkname = Collection::from($this |
137 | 137 | ->query( |
138 | 138 | "SELECT constraint_name FROM information_schema.table_constraints |
139 | 139 | WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?", |
140 | - [ $table, 'PRIMARY KEY', $schema, $catalog ] |
|
140 | + [$table, 'PRIMARY KEY', $schema, $catalog] |
|
141 | 141 | )) |
142 | 142 | ->pluck('constraint_name') |
143 | 143 | ->value(); |
@@ -147,12 +147,12 @@ discard block |
||
147 | 147 | ->query( |
148 | 148 | "SELECT column_name FROM information_schema.constraint_column_usage |
149 | 149 | WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?", |
150 | - [ $table, $pkname, $schema, $catalog ] |
|
150 | + [$table, $pkname, $schema, $catalog] |
|
151 | 151 | )) |
152 | 152 | ->pluck('column_name') |
153 | 153 | ->toArray(); |
154 | 154 | } |
155 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
155 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
156 | 156 | ->addColumns($columns) |
157 | 157 | ->setPrimaryKey($primary) |
158 | 158 | ->setComment(''); |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | // assuming current table is on the "one" end having "many" records in the referencing table |
163 | 163 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
164 | 164 | $relations = []; |
165 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
166 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . |
|
165 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
166 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'. |
|
167 | 167 | $relation['table_name']; |
168 | 168 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
169 | 169 | $relation['column_name']; |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | $usedcol = []; |
181 | 181 | if (count($columns)) { |
182 | 182 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
183 | - ->filter(function ($v) use ($columns) { |
|
183 | + ->filter(function($v) use ($columns) { |
|
184 | 184 | return in_array($v['column_name'], $columns); |
185 | 185 | }) as $relation |
186 | 186 | ) { |
187 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
187 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
188 | 188 | $relation['referenced_table_name']; |
189 | 189 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
190 | 190 | $relation['referenced_column_name']; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $definition->getName() == $relname || |
205 | 205 | $definition->getColumn($relname) |
206 | 206 | ) { |
207 | - $relname = $orig . '_' . (++ $cntr); |
|
207 | + $relname = $orig.'_'.(++$cntr); |
|
208 | 208 | } |
209 | 209 | $definition->addRelation( |
210 | 210 | new TableRelation( |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $definition->getName() == $relname || |
229 | 229 | $definition->getColumn($relname) |
230 | 230 | ) { |
231 | - $relname = $orig . '_' . (++ $cntr); |
|
231 | + $relname = $orig.'_'.(++$cntr); |
|
232 | 232 | } |
233 | 233 | $definition->addRelation( |
234 | 234 | new TableRelation( |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | // assuming current table is linked to "one" record in the referenced table |
245 | 245 | // resulting in a "belongsTo" relationship |
246 | 246 | $relations = []; |
247 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
248 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
247 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
248 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
249 | 249 | $relation['referenced_table_name']; |
250 | 250 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
251 | 251 | $relation['referenced_column_name']; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $definition->getName() == $relname || |
263 | 263 | $definition->getColumn($relname) |
264 | 264 | ) { |
265 | - $relname = $orig . '_' . (++ $cntr); |
|
265 | + $relname = $orig.'_'.(++$cntr); |
|
266 | 266 | } |
267 | 267 | $definition->addRelation( |
268 | 268 | new TableRelation( |
@@ -281,19 +281,19 @@ discard block |
||
281 | 281 | $tables = Collection::from($this |
282 | 282 | ->query( |
283 | 283 | "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?", |
284 | - [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ] |
|
284 | + [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']] |
|
285 | 285 | )) |
286 | - ->mapKey(function ($v) { |
|
286 | + ->mapKey(function($v) { |
|
287 | 287 | return strtolower($v['table_name']); |
288 | 288 | }) |
289 | 289 | ->pluck('table_name') |
290 | - ->map(function ($v) { |
|
290 | + ->map(function($v) { |
|
291 | 291 | return $this->table($v)->toLowerCase(); |
292 | 292 | }) |
293 | 293 | ->toArray(); |
294 | 294 | |
295 | 295 | foreach (array_keys($tables) as $k) { |
296 | - $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k]; |
|
296 | + $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k]; |
|
297 | 297 | } |
298 | 298 | return $tables; |
299 | 299 | } |