@@ -55,7 +55,7 @@ |
||
55 | 55 | } |
56 | 56 | public function next() |
57 | 57 | { |
58 | - $this->fetched ++; |
|
58 | + $this->fetched++; |
|
59 | 59 | $this->last = $this->statement->fetch(\PDO::FETCH_ASSOC); |
60 | 60 | } |
61 | 61 | public function valid() |
@@ -44,7 +44,7 @@ |
||
44 | 44 | isset($this->connection['opts']) ? $this->connection['opts'] : [] |
45 | 45 | ); |
46 | 46 | } catch (\PDOException $e) { |
47 | - throw new DBException('Connect error: ' . $e->getMessage()); |
|
47 | + throw new DBException('Connect error: '.$e->getMessage()); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | $instance->setDefault($data['default']); |
48 | 48 | } |
49 | 49 | if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) { |
50 | - $temp = array_map(function ($v) { |
|
50 | + $temp = array_map(function($v) { |
|
51 | 51 | return str_replace("''", "'", $v); |
52 | 52 | }, explode("','", substr($instance->getType(), 6, -2))); |
53 | 53 | $instance->setValues($temp); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public function setPrimaryKey($column) : Table |
79 | 79 | { |
80 | 80 | if (!is_array($column)) { |
81 | - $column = [ $column ]; |
|
81 | + $column = [$column]; |
|
82 | 82 | } |
83 | 83 | $this->data['primary'] = $column; |
84 | 84 | return $this; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | } |
166 | 166 | |
167 | 167 | if (!isset($name)) { |
168 | - $name = $toTable->getName() . '_' . implode('_', array_keys($keymap)); |
|
168 | + $name = $toTable->getName().'_'.implode('_', array_keys($keymap)); |
|
169 | 169 | } |
170 | 170 | $this->addRelation(new TableRelation( |
171 | 171 | $name, |
@@ -83,7 +83,7 @@ |
||
83 | 83 | } |
84 | 84 | } |
85 | 85 | if (!$this->statement->execute()) { |
86 | - throw new DBException('Prepared execute error: ' . $this->statement->error); |
|
86 | + throw new DBException('Prepared execute error: '.$this->statement->error); |
|
87 | 87 | } |
88 | 88 | return new Result($this->statement); |
89 | 89 | } |
@@ -74,8 +74,7 @@ discard block |
||
74 | 74 | } |
75 | 75 | $connection['name'] = $connectionString; |
76 | 76 | $connection['type'] = isset($aliases[$connection['type']]) ? |
77 | - $aliases[$connection['type']] : |
|
78 | - $connection['type']; |
|
77 | + $aliases[$connection['type']] : $connection['type']; |
|
79 | 78 | $tmp = '\\vakata\\database\\driver\\'.strtolower($connection['type']).'\\Driver'; |
80 | 79 | return new $tmp($connection); |
81 | 80 | } |
@@ -95,7 +94,7 @@ discard block |
||
95 | 94 | $new = ''; |
96 | 95 | $par = array_values($par); |
97 | 96 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
98 | - $par = [ $par ]; |
|
97 | + $par = [$par]; |
|
99 | 98 | } |
100 | 99 | $parts = explode('??', $sql); |
101 | 100 | $index = 0; |
@@ -105,7 +104,7 @@ discard block |
||
105 | 104 | $index += count($tmp) - 1; |
106 | 105 | if (isset($par[$index])) { |
107 | 106 | if (!is_array($par[$index])) { |
108 | - $par[$index] = [ $par[$index] ]; |
|
107 | + $par[$index] = [$par[$index]]; |
|
109 | 108 | } |
110 | 109 | $params = $par[$index]; |
111 | 110 | array_splice($par, $index, 1, $params); |
@@ -113,7 +112,7 @@ discard block |
||
113 | 112 | $new .= implode(',', array_fill(0, count($params), '?')); |
114 | 113 | } |
115 | 114 | } |
116 | - return [ $new, $par ]; |
|
115 | + return [$new, $par]; |
|
117 | 116 | } |
118 | 117 | /** |
119 | 118 | * Run a query (prepare & execute). |
@@ -145,7 +144,7 @@ discard block |
||
145 | 144 | { |
146 | 145 | $coll = Collection::from($this->query($sql, $par)); |
147 | 146 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
148 | - $coll->map(function ($v) use ($keys) { |
|
147 | + $coll->map(function($v) use ($keys) { |
|
149 | 148 | $new = []; |
150 | 149 | foreach ($v as $k => $vv) { |
151 | 150 | $new[call_user_func($keys, $k)] = $vv; |
@@ -154,13 +153,13 @@ discard block |
||
154 | 153 | }); |
155 | 154 | } |
156 | 155 | if ($key !== null) { |
157 | - $coll->mapKey(function ($v) use ($key) { return $v[$key]; }); |
|
156 | + $coll->mapKey(function($v) use ($key) { return $v[$key]; }); |
|
158 | 157 | } |
159 | 158 | if ($skip) { |
160 | - $coll->map(function ($v) use ($key) { unset($v[$key]); return $v; }); |
|
159 | + $coll->map(function($v) use ($key) { unset($v[$key]); return $v; }); |
|
161 | 160 | } |
162 | 161 | if ($opti) { |
163 | - $coll->map(function ($v) { return count($v) === 1 ? current($v) : $v; }); |
|
162 | + $coll->map(function($v) { return count($v) === 1 ? current($v) : $v; }); |
|
164 | 163 | } |
165 | 164 | return $coll; |
166 | 165 | } |
@@ -233,8 +232,7 @@ discard block |
||
233 | 232 | public function definition(string $table, bool $detectRelations = true) : Table |
234 | 233 | { |
235 | 234 | return isset($this->tables[$table]) ? |
236 | - $this->tables[$table] : |
|
237 | - $this->driver->table($table, $detectRelations); |
|
235 | + $this->tables[$table] : $this->driver->table($table, $detectRelations); |
|
238 | 236 | } |
239 | 237 | /** |
240 | 238 | * Parse all tables from the database. |
@@ -251,12 +249,12 @@ discard block |
||
251 | 249 | */ |
252 | 250 | public function getSchema($asPlainArray = true) |
253 | 251 | { |
254 | - return !$asPlainArray ? $this->tables : array_map(function ($table) { |
|
252 | + return !$asPlainArray ? $this->tables : array_map(function($table) { |
|
255 | 253 | return [ |
256 | 254 | 'name' => $table->getName(), |
257 | 255 | 'pkey' => $table->getPrimaryKey(), |
258 | 256 | 'comment' => $table->getComment(), |
259 | - 'columns' => array_map(function ($column) { |
|
257 | + 'columns' => array_map(function($column) { |
|
260 | 258 | return [ |
261 | 259 | 'name' => $column->getName(), |
262 | 260 | 'type' => $column->getType(), |
@@ -266,13 +264,13 @@ discard block |
||
266 | 264 | 'nullable' => $column->isNullable() |
267 | 265 | ]; |
268 | 266 | }, $table->getFullColumns()), |
269 | - 'relations' => array_map(function ($rel) { |
|
267 | + 'relations' => array_map(function($rel) { |
|
270 | 268 | $relation = clone $rel; |
271 | 269 | $relation->table = $relation->table->getName(); |
272 | 270 | if ($relation->pivot) { |
273 | 271 | $relation->pivot = $relation->pivot->getName(); |
274 | 272 | } |
275 | - return (array)$relation; |
|
273 | + return (array) $relation; |
|
276 | 274 | }, $table->getRelations()) |
277 | 275 | ]; |
278 | 276 | }, $this->tables); |
@@ -124,16 +124,16 @@ discard block |
||
124 | 124 | $columns = Collection::from($this |
125 | 125 | ->query( |
126 | 126 | "SELECT * FROM all_tab_cols WHERE table_name = ? AND owner = ?", |
127 | - [ strtoupper($table), $this->name() ] |
|
127 | + [strtoupper($table), $this->name()] |
|
128 | 128 | )) |
129 | - ->map(function ($v) { |
|
129 | + ->map(function($v) { |
|
130 | 130 | $new = []; |
131 | 131 | foreach ($v as $kk => $vv) { |
132 | 132 | $new[strtoupper($kk)] = $vv; |
133 | 133 | } |
134 | 134 | return $new; |
135 | 135 | }) |
136 | - ->mapKey(function ($v) { return $v['COLUMN_NAME']; }) |
|
136 | + ->mapKey(function($v) { return $v['COLUMN_NAME']; }) |
|
137 | 137 | ->toArray(); |
138 | 138 | if (!count($columns)) { |
139 | 139 | throw new DBException('Table not found by name'); |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | ->query( |
144 | 144 | "SELECT constraint_name FROM all_constraints |
145 | 145 | WHERE table_name = ? AND constraint_type = ? AND owner = ?", |
146 | - [ strtoupper($table), 'P', $owner ] |
|
146 | + [strtoupper($table), 'P', $owner] |
|
147 | 147 | )) |
148 | - ->map(function ($v) { |
|
148 | + ->map(function($v) { |
|
149 | 149 | $new = []; |
150 | 150 | foreach ($v as $kk => $vv) { |
151 | 151 | $new[strtoupper($kk)] = $vv; |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | ->query( |
161 | 161 | "SELECT column_name FROM all_cons_columns |
162 | 162 | WHERE table_name = ? AND constraint_name = ? AND owner = ?", |
163 | - [ strtoupper($table), $pkname, $owner ] |
|
163 | + [strtoupper($table), $pkname, $owner] |
|
164 | 164 | )) |
165 | - ->map(function ($v) { |
|
165 | + ->map(function($v) { |
|
166 | 166 | $new = []; |
167 | 167 | foreach ($v as $kk => $vv) { |
168 | 168 | $new[strtoupper($kk)] = $vv; |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
190 | 190 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
191 | 191 | ORDER BY cc.POSITION", |
192 | - [ $owner, $owner, $pkname, 'R' ] |
|
192 | + [$owner, $owner, $pkname, 'R'] |
|
193 | 193 | )) |
194 | - ->map(function ($v) { |
|
194 | + ->map(function($v) { |
|
195 | 195 | $new = []; |
196 | 196 | foreach ($v as $kk => $vv) { |
197 | 197 | $new[strtoupper($kk)] = $vv; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | as $relation |
202 | 202 | ) { |
203 | 203 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
204 | - $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = $relation['COLUMN_NAME']; |
|
204 | + $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = $relation['COLUMN_NAME']; |
|
205 | 205 | } |
206 | 206 | foreach ($relations as $data) { |
207 | 207 | $rtable = $this->table($data['table'], true); |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND |
226 | 226 | cc.COLUMN_NAME IN (??) |
227 | 227 | ORDER BY POSITION", |
228 | - [ $owner, $owner, $data['table'], 'R', $columns ] |
|
228 | + [$owner, $owner, $data['table'], 'R', $columns] |
|
229 | 229 | )) |
230 | - ->map(function ($v) { |
|
230 | + ->map(function($v) { |
|
231 | 231 | $new = []; |
232 | 232 | foreach ($v as $kk => $vv) { |
233 | 233 | $new[strtoupper($kk)] = $vv; |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | $rcolumns = Collection::from($this |
246 | 246 | ->query( |
247 | 247 | "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
248 | - [ $owner, current($foreign['keymap']) ] |
|
248 | + [$owner, current($foreign['keymap'])] |
|
249 | 249 | )) |
250 | - ->map(function ($v) { |
|
250 | + ->map(function($v) { |
|
251 | 251 | $new = []; |
252 | 252 | foreach ($v as $kk => $vv) { |
253 | 253 | $new[strtoupper($kk)] = $vv; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $relname = $foreign['table']; |
263 | 263 | $cntr = 1; |
264 | 264 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
265 | - $relname = $foreign['table'] . '_' . (++ $cntr); |
|
265 | + $relname = $foreign['table'].'_'.(++$cntr); |
|
266 | 266 | } |
267 | 267 | $definition->addRelation( |
268 | 268 | new TableRelation( |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $relname = $data['table']; |
279 | 279 | $cntr = 1; |
280 | 280 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
281 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
281 | + $relname = $data['table'].'_'.(++$cntr); |
|
282 | 282 | } |
283 | 283 | $definition->addRelation( |
284 | 284 | new TableRelation( |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
303 | 303 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
304 | 304 | ORDER BY cc.POSITION", |
305 | - [ $owner, $owner, strtoupper($table), 'R' ] |
|
305 | + [$owner, $owner, strtoupper($table), 'R'] |
|
306 | 306 | )) |
307 | - ->map(function ($v) { |
|
307 | + ->map(function($v) { |
|
308 | 308 | $new = []; |
309 | 309 | foreach ($v as $kk => $vv) { |
310 | 310 | $new[strtoupper($kk)] = $vv; |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | $rcolumns = Collection::from($this |
321 | 321 | ->query( |
322 | 322 | "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
323 | - [ $owner, current($data['keymap']) ] |
|
323 | + [$owner, current($data['keymap'])] |
|
324 | 324 | )) |
325 | - ->map(function ($v) { |
|
325 | + ->map(function($v) { |
|
326 | 326 | $new = []; |
327 | 327 | foreach ($v as $kk => $vv) { |
328 | 328 | $new[strtoupper($kk)] = $vv; |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $relname = $data['table']; |
338 | 338 | $cntr = 1; |
339 | 339 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
340 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
340 | + $relname = $data['table'].'_'.(++$cntr); |
|
341 | 341 | } |
342 | 342 | $definition->addRelation( |
343 | 343 | new TableRelation( |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | "SELECT TABLE_NAME FROM ALL_TABLES where OWNER = ?", |
359 | 359 | [$this->connection['name']] |
360 | 360 | )) |
361 | - ->map(function ($v) { |
|
361 | + ->map(function($v) { |
|
362 | 362 | $new = []; |
363 | 363 | foreach ($v as $kk => $vv) { |
364 | 364 | $new[strtoupper($kk)] = $vv; |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | return $new; |
367 | 367 | }) |
368 | 368 | ->pluck('TABLE_NAME') |
369 | - ->map(function ($v) { |
|
369 | + ->map(function($v) { |
|
370 | 370 | return $this->table($v); |
371 | 371 | }) |
372 | 372 | ->toArray(); |
@@ -74,7 +74,7 @@ |
||
74 | 74 | } |
75 | 75 | public function next() |
76 | 76 | { |
77 | - $this->fetched ++; |
|
77 | + $this->fetched++; |
|
78 | 78 | $temp = \odbc_fetch_row($this->statement); |
79 | 79 | if (!$temp) { |
80 | 80 | $this->last = false; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $fields = []; |
71 | 71 | $exists = false; |
72 | 72 | foreach ($relation->table->getColumns() as $column) { |
73 | - $nm = $name . static::SEP . $column; |
|
73 | + $nm = $name.static::SEP.$column; |
|
74 | 74 | if (isset($this->aliases[$nm])) { |
75 | 75 | $nm = $this->aliases[$nm]; |
76 | 76 | } |
@@ -84,16 +84,16 @@ discard block |
||
84 | 84 | $parts = explode(static::SEP, $name); |
85 | 85 | $name = array_pop($parts); |
86 | 86 | if (!$exists && !count($parts) && !isset($temp[$name])) { |
87 | - $temp[$name] = $relation->many ? [ '___clean' => true ] : null; |
|
87 | + $temp[$name] = $relation->many ? ['___clean' => true] : null; |
|
88 | 88 | } |
89 | 89 | if ($exists) { |
90 | - $full = ''; |
|
90 | + $full = ''; |
|
91 | 91 | foreach ($parts as $item) { |
92 | - $full = $full ? $full . static::SEP . $item : $item; |
|
92 | + $full = $full ? $full.static::SEP.$item : $item; |
|
93 | 93 | $temp = &$temp[$item]; |
94 | 94 | $rpk = []; |
95 | 95 | foreach ($this->relations[$full][0]->table->getPrimaryKey() as $pkey) { |
96 | - $nm = $full . static::SEP . $pkey; |
|
96 | + $nm = $full.static::SEP.$pkey; |
|
97 | 97 | if (isset($this->aliases[$nm])) { |
98 | 98 | $nm = $this->aliases[$nm]; |
99 | 99 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $temp = &$temp[json_encode($rpk)]; |
103 | 103 | } |
104 | 104 | if (!isset($temp[$name])) { |
105 | - $temp[$name] = $relation->many ? [ '___clean' => true ] : null; |
|
105 | + $temp[$name] = $relation->many ? ['___clean' => true] : null; |
|
106 | 106 | } |
107 | 107 | $temp = &$temp[$name]; |
108 | 108 | if ($relation->many) { |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | return; |
161 | 161 | } |
162 | 162 | } |
163 | - $this->fetched ++; |
|
163 | + $this->fetched++; |
|
164 | 164 | while ($this->result->valid()) { |
165 | 165 | $row = $this->result->current(); |
166 | 166 | $pk = []; |