Completed
Push — master ( 036ee8...c67404 )
by Ivan
03:01
created
src/driver/postgre/Driver.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
                      JOIN information_schema.constraint_table_usage ct ON kc.constraint_name = ct.constraint_name AND ct.table_schema = kc.table_schema
148 148
                      WHERE
149 149
                         kc.table_schema = ? AND kc.table_name IS NOT NULL AND kc.position_in_unique_constraint IS NOT NULL",
150
-                    [ $this->connection['opts']['schema'] ?? $this->connection['name'] ]
150
+                    [$this->connection['opts']['schema'] ?? $this->connection['name']]
151 151
                 )
152 152
             )->toArray();
153 153
             foreach ($col as $row) {
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
         $columns = Collection::from($this
160 160
             ->query(
161 161
                 "SELECT * FROM information_schema.columns WHERE table_name = ? AND table_schema = ?",
162
-                [ $table, $this->connection['opts']['schema'] ?? $this->connection['name'] ]
162
+                [$table, $this->connection['opts']['schema'] ?? $this->connection['name']]
163 163
             ))
164
-            ->mapKey(function ($v) { return $v['column_name']; })
165
-            ->map(function ($v) {
164
+            ->mapKey(function($v) { return $v['column_name']; })
165
+            ->map(function($v) {
166 166
                 $v['length'] = null;
167 167
                 if (!isset($v['data_type'])) {
168 168
                     return $v;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
                 switch ($v['data_type']) {
171 171
                     case 'character':
172 172
                     case 'character varying':
173
-                        $v['length'] = (int)$v['character_maximum_length'];
173
+                        $v['length'] = (int) $v['character_maximum_length'];
174 174
                         break;
175 175
                 }
176 176
                 return $v;
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
             ->query(
184 184
                 "SELECT constraint_name FROM information_schema.table_constraints
185 185
                 WHERE table_name = ? AND constraint_type = ? AND table_schema = ?",
186
-                [ $table, 'PRIMARY KEY', $this->connection['opts']['schema'] ?? $this->connection['name'] ]
186
+                [$table, 'PRIMARY KEY', $this->connection['opts']['schema'] ?? $this->connection['name']]
187 187
             ))
188 188
             ->pluck('constraint_name')
189 189
             ->value();
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
                 ->query(
194 194
                     "SELECT column_name FROM information_schema.constraint_column_usage
195 195
                      WHERE table_name = ? AND constraint_name = ? AND table_schema = ?",
196
-                    [ $table, $pkname, $this->connection['opts']['schema'] ?? $this->connection['name'] ]
196
+                    [$table, $pkname, $this->connection['opts']['schema'] ?? $this->connection['name']]
197 197
                 ))
198 198
                 ->pluck('column_name')
199 199
                 ->toArray();
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
                 $usedcol = [];
225 225
                 if (count($columns)) {
226 226
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
227
-                        ->filter(function ($v) use ($columns) {
227
+                        ->filter(function($v) use ($columns) {
228 228
                             return in_array($v['column_name'], $columns);
229 229
                         }) as $relation
230 230
                     ) {
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
                     $relname = $foreign['table'];
239 239
                     $cntr = 1;
240 240
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
241
-                        $relname = $foreign['table'] . '_' . (++ $cntr);
241
+                        $relname = $foreign['table'].'_'.(++$cntr);
242 242
                     }
243 243
                     $definition->addRelation(
244 244
                         new TableRelation(
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
                     $relname = $data['table'];
255 255
                     $cntr = 1;
256 256
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
257
-                        $relname = $data['table'] . '_' . (++ $cntr);
257
+                        $relname = $data['table'].'_'.(++$cntr);
258 258
                     }
259 259
                     $definition->addRelation(
260 260
                         new TableRelation(
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
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(
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
         return Collection::from($this
298 298
             ->query(
299 299
                 "SELECT table_name FROM information_schema.tables where table_schema = ?",
300
-                [ $this->connection['opts']['schema'] ?? $this->connection['name'] ]
300
+                [$this->connection['opts']['schema'] ?? $this->connection['name']]
301 301
             ))
302 302
             ->pluck('table_name')
303
-            ->map(function ($v) {
303
+            ->map(function($v) {
304 304
                 return $this->table($v);
305 305
             })
306 306
             ->toArray();
Please login to merge, or discard this patch.
src/DB.php 1 patch
Spacing   +14 added lines, -17 removed lines patch added patch discarded remove patch
@@ -75,8 +75,7 @@  discard block
 block discarded – undo
75 75
         }
76 76
         $connection['name'] = $connectionString;
77 77
         $connection['type'] = isset($aliases[$connection['type']]) ?
78
-            $aliases[$connection['type']] :
79
-            $connection['type'];
78
+            $aliases[$connection['type']] : $connection['type'];
80 79
         $tmp = '\\vakata\\database\\driver\\'.strtolower($connection['type']).'\\Driver';
81 80
         return new $tmp($connection);
82 81
     }
@@ -105,7 +104,7 @@  discard block
 block discarded – undo
105 104
         $new = '';
106 105
         $par = array_values($par);
107 106
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
108
-            $par = [ $par ];
107
+            $par = [$par];
109 108
         }
110 109
         $parts = explode('??', $sql);
111 110
         $index = 0;
@@ -115,7 +114,7 @@  discard block
 block discarded – undo
115 114
             $index += count($tmp) - 1;
116 115
             if (isset($par[$index])) {
117 116
                 if (!is_array($par[$index])) {
118
-                    $par[$index] = [ $par[$index] ];
117
+                    $par[$index] = [$par[$index]];
119 118
                 }
120 119
                 $params = $par[$index];
121 120
                 array_splice($par, $index, 1, $params);
@@ -123,7 +122,7 @@  discard block
 block discarded – undo
123 122
                 $new .= implode(',', array_fill(0, count($params), '?'));
124 123
             }
125 124
         }
126
-        return [ $new, $par ];
125
+        return [$new, $par];
127 126
     }
128 127
     /**
129 128
      * Run a query (prepare & execute).
@@ -155,7 +154,7 @@  discard block
 block discarded – undo
155 154
     {
156 155
         $coll = Collection::from($this->query($sql, $par));
157 156
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
158
-            $coll->map(function ($v) use ($keys) {
157
+            $coll->map(function($v) use ($keys) {
159 158
                 $new = [];
160 159
                 foreach ($v as $k => $vv) {
161 160
                     $new[call_user_func($keys, $k)] = $vv;
@@ -164,13 +163,13 @@  discard block
 block discarded – undo
164 163
             });
165 164
         }
166 165
         if ($key !== null) {
167
-            $coll->mapKey(function ($v) use ($key) { return $v[$key]; });
166
+            $coll->mapKey(function($v) use ($key) { return $v[$key]; });
168 167
         }
169 168
         if ($skip) {
170
-            $coll->map(function ($v) use ($key) { unset($v[$key]); return $v; });
169
+            $coll->map(function($v) use ($key) { unset($v[$key]); return $v; });
171 170
         }
172 171
         if ($opti) {
173
-            $coll->map(function ($v) { return count($v) === 1 ? current($v) : $v; });
172
+            $coll->map(function($v) { return count($v) === 1 ? current($v) : $v; });
174 173
         }
175 174
         return $coll;
176 175
     }
@@ -254,8 +253,7 @@  discard block
 block discarded – undo
254 253
     public function definition(string $table, bool $detectRelations = true) : Table
255 254
     {
256 255
         return isset($this->tables[$table]) ?
257
-            $this->tables[$table] :
258
-            $this->driver->table($table, $detectRelations);
256
+            $this->tables[$table] : $this->driver->table($table, $detectRelations);
259 257
     }
260 258
     /**
261 259
      * Parse all tables from the database.
@@ -272,12 +270,12 @@  discard block
 block discarded – undo
272 270
      */
273 271
     public function getSchema($asPlainArray = true)
274 272
     {
275
-        return !$asPlainArray ? $this->tables : array_map(function ($table) {
273
+        return !$asPlainArray ? $this->tables : array_map(function($table) {
276 274
             return [
277 275
                 'name' => $table->getName(),
278 276
                 'pkey' => $table->getPrimaryKey(),
279 277
                 'comment' => $table->getComment(),
280
-                'columns' => array_map(function ($column) {
278
+                'columns' => array_map(function($column) {
281 279
                     return [
282 280
                         'name' => $column->getName(),
283 281
                         'type' => $column->getType(),
@@ -288,13 +286,13 @@  discard block
 block discarded – undo
288 286
                         'nullable' => $column->isNullable()
289 287
                     ];
290 288
                 }, $table->getFullColumns()),
291
-                'relations' => array_map(function ($rel) {
289
+                'relations' => array_map(function($rel) {
292 290
                     $relation = clone $rel;
293 291
                     $relation->table = $relation->table->getName();
294 292
                     if ($relation->pivot) {
295 293
                         $relation->pivot = $relation->pivot->getName();
296 294
                     }
297
-                    return (array)$relation;
295
+                    return (array) $relation;
298 296
                 }, $table->getRelations())
299 297
             ];
300 298
         }, $this->tables);
@@ -342,8 +340,7 @@  discard block
 block discarded – undo
342 340
     public function table($table, bool $mapped = false)
343 341
     {
344 342
         return $mapped ?
345
-            new TableQueryMapped($this, $this->definition($table)) :
346
-            new TableQuery($this, $this->definition($table));
343
+            new TableQueryMapped($this, $this->definition($table)) : new TableQuery($this, $this->definition($table));
347 344
     }
348 345
     public function __call($method, $args)
349 346
     {
Please login to merge, or discard this patch.
src/schema/Mapper.php 2 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,6 +43,10 @@  discard block
 block discarded – undo
43 43
             protected $changed = [];
44 44
             protected $fetched = [];
45 45
 
46
+            /**
47
+             * @param Mapper $mapper
48
+             * @param Table $definition
49
+             */
46 50
             public function __construct($mapper, $definition, array $data = [])
47 51
             {
48 52
                 $this->mapper = $mapper;
@@ -156,7 +160,7 @@  discard block
 block discarded – undo
156 160
     /**
157 161
      * Get a collection of entities
158 162
      *
159
-     * @param TableQuery $iterator
163
+     * @param TableQueryIterator $iterator
160 164
      * @param Table $definition
161 165
      * @return Collection
162 166
      */
Please login to merge, or discard this patch.
Spacing   +8 added lines, -11 removed lines patch added patch discarded remove patch
@@ -58,8 +58,7 @@  discard block
 block discarded – undo
58 58
             {
59 59
                 if (isset($this->fetched[$property])) {
60 60
                     return is_callable($this->fetched[$property]) ?
61
-                        $this->fetched[$property] = call_user_func($this->fetched[$property]) :
62
-                        $this->fetched[$property];
61
+                        $this->fetched[$property] = call_user_func($this->fetched[$property]) : $this->fetched[$property];
63 62
                 }
64 63
                 if (isset($this->changed[$property])) {
65 64
                     return $this->changed[$property];
@@ -78,8 +77,7 @@  discard block
 block discarded – undo
78 77
                 if (isset($this->definition->getRelations()[$method])) {
79 78
                     if (isset($this->fetched[$method])) {
80 79
                         return is_callable($this->fetched[$method]) ?
81
-                            $this->fetched[$method] = call_user_func($this->fetched[$method], $args[0] ?? null) :
82
-                            $this->fetched[$method];
80
+                            $this->fetched[$method] = call_user_func($this->fetched[$method], $args[0] ?? null) : $this->fetched[$method];
83 81
                     }
84 82
                 }
85 83
                 return null;
@@ -163,7 +161,7 @@  discard block
 block discarded – undo
163 161
     public function collection(TableQueryIterator $iterator, Table $definition) : Collection
164 162
     {
165 163
         return Collection::from($iterator)
166
-            ->map(function ($v) use ($definition) {
164
+            ->map(function($v) use ($definition) {
167 165
                 return $this->entity($definition, $v);
168 166
             });
169 167
     }
@@ -238,7 +236,7 @@  discard block
 block discarded – undo
238 236
         $definition = $entity->definition();
239 237
         foreach ($definition->getColumns() as $column) {
240 238
             if (!isset($data[$column])) {
241
-                $entity->__lazyProperty($column, function () use ($entity, $definition, $primary, $column) {
239
+                $entity->__lazyProperty($column, function() use ($entity, $definition, $primary, $column) {
242 240
                     $query = $this->db->table($definition->getName());
243 241
                     foreach ($primary as $k => $v) {
244 242
                         $query->filter($k, $v);
@@ -252,12 +250,12 @@  discard block
 block discarded – undo
252 250
                 $name,
253 251
                 isset($data[$name]) ?
254 252
                     ($relation->many ? 
255
-                        array_map(function ($v) use ($relation) {
253
+                        array_map(function($v) use ($relation) {
256 254
                             return $this->entity($relation->table, $v);
257 255
                         }, $data[$name]) :
258 256
                         $this->entity($relation->table, $data[$name])
259 257
                     ) :
260
-                    function (array $columns = null) use ($entity, $definition, $primary, $relation, $data) {
258
+                    function(array $columns = null) use ($entity, $definition, $primary, $relation, $data) {
261 259
                         $query = $this->db->table($relation->table->getName(), true);
262 260
                         if ($columns !== null) {
263 261
                             $query->columns($columns);
@@ -283,7 +281,7 @@  discard block
 block discarded – undo
283 281
                                 );
284 282
                             }
285 283
                             foreach ($definition->getPrimaryKey() as $v) {
286
-                                $query->filter($nm . '.' . $v, $data[$v] ?? null);
284
+                                $query->filter($nm.'.'.$v, $data[$v] ?? null);
287 285
                             }
288 286
                         } else {
289 287
                             foreach ($relation->keymap as $k => $v) {
@@ -291,8 +289,7 @@  discard block
 block discarded – undo
291 289
                             }
292 290
                         }
293 291
                         return $relation->many ?
294
-                            $query->iterator() :
295
-                            $query[0];
292
+                            $query->iterator() : $query[0];
296 293
                     }
297 294
             );
298 295
         }
Please login to merge, or discard this patch.