Passed
Push — master ( 7af85f...e5caec )
by Dāvis
03:24
created

QuickInsertRepository   F

Complexity

Total Complexity 136

Size/Duplication

Total Lines 512
Duplicated Lines 16.41 %

Importance

Changes 0
Metric Value
dl 84
loc 512
rs 1.5789
c 0
b 0
f 0
wmc 136

14 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 16 4
A close() 0 5 2
B isEmpty() 0 13 5
A extract() 0 7 1
B extractExt() 0 24 4
C buildWhere() 30 54 26
B findNextId() 0 24 3
C buildExtra() 0 38 8
D update() 20 83 20
A findNextIdExt() 0 6 1
B link() 0 30 6
F persist() 34 99 35
D get() 0 57 18
A delete() 0 18 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like QuickInsertRepository often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use QuickInsertRepository, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Sludio\HelperBundle\Script\Repository;
4
5
class QuickInsertRepository
6
{
7
    private static $mock = [];
8
    private static $metadata = [];
9
    private static $tableName;
10
11
    public static $em;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $em. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
12
    public static $connection;
13
    public static $container;
14
15
    public static function init($noFkCheck = false, $manager = null)
0 ignored issues
show
Coding Style introduced by
This method's name is shorter than the configured minimum length of 5 characters.

Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.

Loading history...
16
    {
17
        global $kernel;
18
19
        if ('AppCache' === get_class($kernel)) {
20
            $kernel = $kernel->getKernel();
21
        }
22
        self::$container = $kernel->getContainer();
23
24
        $manager = $manager ?: self::$container->getParameter('sludio_helper.entity.manager');
25
        self::$em = self::$container->get('doctrine')->getManager($manager);
26
        self::$connection = self::$em->getConnection();
27
28
        if (!$noFkCheck) {
29
            $sth = self::$connection->prepare('SET FOREIGN_KEY_CHECKS = 0');
30
            $sth->execute();
31
        }
32
    }
33
34
    public static function close($noFkCheck = false)
35
    {
36
        if (!$noFkCheck) {
37
            $sth = self::$connection->prepare('SET FOREIGN_KEY_CHECKS = 1');
38
            $sth->execute();
39
        }
40
    }
41
42
    public static function isEmpty($variable)
43
    {
44
        $result = true;
45
46
        if (is_array($variable) && count($variable) > 0) {
47
            foreach ($variable as $value) {
48
                $result = $result && self::isEmpty($value);
49
            }
50
        } else {
51
            $result = empty($variable);
52
        }
53
54
        return $result;
55
    }
56
57
    private static function extract($object)
58
    {
59
        $data = self::extractExt($object, self::$em);
60
61
        self::$mock = $data['mock'];
62
        self::$tableName = $data['table'];
63
        self::$metadata[$data['table']] = $data['meta'];
64
    }
65
66
    public static function extractExt($object, $em)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $em. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
67
    {
68
        $metadata = $em->getClassMetadata(get_class($object));
69
70
        $fields = $metadata->getFieldNames();
71
        $columns = $metadata->getColumnNames();
72
        $table = $metadata->getTableName();
73
74
        $result = [];
75
        foreach ($fields as $key => $field) {
76
            foreach ($columns as $key2 => $column) {
77
                if ($key === $key2) {
78
                    $result[$table][$field] = $column;
79
                }
80
            }
81
        }
82
83
        $data = [
84
            'mock' => $result,
85
            'table' => $table,
86
            'meta' => $metadata,
87
        ];
88
89
        return $data;
90
    }
91
92
    private static function buildExtra($extra)
93
    {
94
        $methods = [
95
            'GROUP BY',
96
            'HAVING',
97
            'ORDER BY',
98
        ];
99
        $sql = '';
100
101
        foreach ($methods as $method) {
102
            if (isset($extra[$method])) {
103
                $sql .= ' '.$method.' ';
104
                if (is_array($extra[$method])) {
105
                    foreach ($extra[$method] as $group) {
106
                        $sql .= $group.' ';
107
                    }
108
                } else {
109
                    $sql .= $extra[$method].' ';
110
                }
111
            }
112
        }
113
114
        if (isset($extra['LIMIT'])) {
115
            if (is_array($extra['LIMIT'])) {
116
                if (isset($extra['LIMIT'][1])) {
117
                    $offset = $extra['LIMIT'][0];
118
                    $limit = $extra['LIMIT'][1];
119
                } else {
120
                    $offset = 0;
121
                    $limit = $extra['LIMIT'][0];
122
                }
123
                $sql .= 'LIMIT '.$offset.', '.$limit;
124
            }
125
        }
126
127
        $sql = str_replace('  ', ' ', $sql);
128
129
        return $sql;
130
    }
131
132
    private static function buildWhere($tableName, $where)
133
    {
134
        $whereSql = $f = $fk = '';
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $f. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $fk. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
135
        if ($where && is_array($where)) {
136
            $skip = false;
137
            foreach ($where as $key => $value) {
138
                $fk = $key;
139
                if (is_array($value)) {
140
                    $skip = true;
141
                    $f = trim($value[0]);
142
                } else {
143
                    $f = trim($value);
144
                }
145
                break;
146
            }
147 View Code Duplication
            if (!$skip && isset(self::$mock[$tableName][$fk])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148
                if (is_numeric($f)) {
149
                    $whereSql .= ' WHERE '.self::$mock[$tableName][$fk]." = $f";
150
                } else {
151
                    $whereSql .= ' WHERE '.self::$mock[$tableName][$fk]." = '".addslashes(trim($f))."'";
152
                }
153
            } else {
154
                if (!$skip && is_numeric($f)) {
155
                    $whereSql .= ' WHERE '.$fk." = $f";
156
                } elseif (!$skip && !is_numeric($f)) {
157
                    $whereSql .= ' WHERE '.$fk." = '".addslashes(trim($f))."'";
158
                } elseif ($skip && is_numeric($fk)) {
159
                    $whereSql .= " WHERE $f";
160
                }
161
            }
162
            unset($where[$fk]);
163
            if ($where && is_array($where)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $where of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
164
                foreach ($where as $key => $value) {
165
                    $skip = is_array($value);
166 View Code Duplication
                    if (!$skip && isset(self::$mock[$tableName][$key])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
167
                        if (is_numeric($value)) {
168
                            $whereSql .= ' AND '.self::$mock[$tableName][$key]." = $value";
169
                        } else {
170
                            $whereSql .= ' AND '.self::$mock[$tableName][$key]." = '".addslashes(trim($value))."'";
171
                        }
172
                    } else {
173
                        if (!$skip && is_numeric($value)) {
174
                            $whereSql .= ' AND '.$key." = $value";
175
                        } elseif (!$skip && !is_numeric($f)) {
176
                            $whereSql .= ' AND '.$key." = '".addslashes(trim($value))."'";
177
                        } elseif ($skip && is_numeric($key)) {
178
                            $whereSql .= " AND {$value[0]}";
179
                        }
180
                    }
181
                }
182
            }
183
        }
184
185
        return $whereSql;
186
    }
187
188
    public static function findNextId($tableName, &$out = null)
189
    {
190
        $sql = "
191
            SELECT
192
                AUTO_INCREMENT
193
            FROM
194
                information_schema.tables
195
            WHERE
196
                table_name = '".$tableName."'
197
            AND
198
                table_schema = DATABASE()
199
        ";
200
        if ($out) {
201
            $out = $sql;
202
        }
203
        $sth = self::$connection->prepare($sql);
204
        $sth->execute();
205
        $result = $sth->fetch();
206
207
        if (isset($result['AUTO_INCREMENT'])) {
208
            return (int)$result['AUTO_INCREMENT'];
209
        }
210
211
        return 1;
212
    }
213
214
    public static function findNextIdExt($object, $em, &$out = null)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $em. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
215
    {
216
        self::init(true, $em);
217
        $data = self::extractExt($object, $em);
218
219
        return self::findNextId($data['table'], $out);
220
    }
221
222
    public static function get($object, $one = false, $where = [], $noFkCheck = true, $fields = [], $manager = null, $extra = [], &$out = null)
0 ignored issues
show
Coding Style introduced by
This method's name is shorter than the configured minimum length of 5 characters.

Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.

Loading history...
223
    {
224
        self::init($noFkCheck, $manager);
225
        if (is_object($object)) {
226
            self::extract($object);
227
            $tableName = self::$tableName;
228
        } else {
229
            $tableName = $object;
230
        }
231
        $whereSql = self::buildWhere($tableName, $where);
232
        $select = (isset($extra['MODE']) ? 'SELECT '.$extra['MODE'] : 'SELECT').' ';
233
        if (!$fields) {
234
            $sql = $select.'id FROM '.$tableName.' '.$whereSql;
235
        } else {
236
            $sql = $select.(implode(', ', $fields)).' FROM '.$tableName.' '.$whereSql;
237
        }
238
        if (!empty($extra)) {
239
            $extraSql = self::buildExtra($extra);
240
            $sql .= $extraSql;
241
        }
242
        if ($out) {
243
            $out = $sql;
244
        }
245
        $sth = self::$connection->prepare($sql);
246
        $sth->execute();
247
        $result = $sth->fetchAll();
248
        if ($one && $result) {
249
            if (!$fields) {
250
                return intval($result[0]['id']);
251
            } else {
252
                if (count($fields) === 1 && $fields[0] !== '*') {
253
                    return $result[0][$fields[0]];
254
                } else {
255
                    return $result[0];
256
                }
257
            }
258
        }
259
260
        self::close($noFkCheck);
261
        if ($one || !$result) {
262
            return null;
263
        }
264
265
        $field = null;
266
        if (!$fields) {
267
            $field = 'id';
268
        } elseif (count($fields) === 1 && $fields[0] !== '*') {
269
            $field = $fields[0];
270
        }
271
272
        if ($field) {
273
            foreach ($result as &$res) {
274
                $res = $res[$field];
275
            }
276
        }
277
278
        return $result;
279
    }
280
281
    public static function persist($object, $full = false, $extraFields = [], $noFkCheck = false, $manager = null, &$out = null)
282
    {
283
        self::init($noFkCheck, $manager);
284 View Code Duplication
        if (is_object($object)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
285
            self::extract($object);
286
            $tableName = self::$tableName;
287
            $columns = self::$mock[$tableName] ?: [];
288
            $type = 'object';
289
        } else {
290
            $tableName = $object['table_name'];
291
            unset($object['table_name']);
292
            $type = 'table';
293
            $columns = array_keys($object) ?: [];
294
        }
295
296
        $id = self::findNextId($tableName);
297
        $keys = [];
298
        $values = [];
299
300 View Code Duplication
        if (!empty($extraFields) && isset($extraFields[$tableName])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
301
            $columns = array_merge($columns, $extraFields[$tableName]);
302
        }
303
304
        if ($type === 'object') {
305
            foreach ($columns as $value => $key) {
306
                $variable = null;
307
                if (!is_array($key) && !is_array($value)) {
308
                    if ($object->{'get'.ucfirst($value)}() instanceof \DateTime) {
309
                        $variable = "'".addslashes(trim($object->{'get'.ucfirst($value)}()->format('Y-m-d H:i:s')))."'";
310
                    } else {
311
                        $variable = "'".addslashes(trim($object->{'get'.ucfirst($value)}()))."'";
312
                    }
313 View Code Duplication
                    if (trim($variable) === '' || trim($variable) === "''" || (is_numeric($variable) && $variable === 0)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
314
                        $variable = null;
315
                    }
316 View Code Duplication
                    if ($variable) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $variable of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
317
                        $values[] = $variable;
318
                        $keys[] = $key;
319
                        if ($key === 'id') {
320
                            $idd = $object->{'get'.ucfirst($value)}();
321
                        }
322
                    }
323
                }
324
            }
325
        } else {
326
            foreach ($columns as $value => $key) {
327
                $variable = null;
328
                if (!is_array($key) && !is_array($value) && isset($object[$value])) {
329
                    if ($object[$value] instanceof \DateTime) {
330
                        $variable = "'".addslashes(trim($object[$value]->format('Y-m-d H:i:s')))."'";
331
                    } else {
332
                        $variable = "'".addslashes(trim($object[$value]))."'";
333
                    }
334 View Code Duplication
                    if (trim($variable) === '' || trim($variable) === "''" || (is_numeric($variable) && $variable === 0)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
335
                        $variable = null;
336
                    }
337 View Code Duplication
                    if ($variable) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $variable of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
338
                        $values[] = $variable;
339
                        $keys[] = $key;
340
                        if ($key === 'id') {
341
                            $idd = $object[$value];
342
                        }
343
                    }
344
                }
345
            }
346
        }
347
348
        $sql = null;
349
        if (!$full && !self::isEmpty($values)) {
350
            $sql = '
351
                INSERT INTO
352
                    '.$tableName.'
353
                        (id, '.implode(',', $keys).")
354
                VALUES
355
                    ({$id},".implode(',', $values).')
356
            ';
357
        } elseif ($full && !self::isEmpty($values)) {
358
            $id = $idd;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $idd does not seem to be defined for all execution paths leading up to this point.
Loading history...
359
            $sql = '
360
                INSERT INTO
361
                    '.$tableName.'
362
                        ('.implode(',', $keys).")
363
                VALUES
364
                    (".implode(',', $values).')
365
            ';
366
        } else {
367
            $id = null;
368
        }
369
        if ($sql && $id) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $sql of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
370
            if ($out) {
371
                $out = $sql;
372
            }
373
            $sth = self::$connection->prepare($sql);
374
            $sth->execute();
375
        }
376
377
        self::close($noFkCheck);
378
379
        return $id;
380
    }
381
382
    public static function update($id, $object, $extraFields = [], $noFkCheck = false, $manager = null, &$out = null)
383
    {
384
        self::init($noFkCheck, $manager);
385
386 View Code Duplication
        if (is_object($object)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
387
            self::extract($object);
388
            $tableName = self::$tableName;
389
            $columns = self::$mock[$tableName] ?: [];
390
            $type = 'object';
391
        } else {
392
            $tableName = $object['table_name'];
393
            unset($object['table_name']);
394
            $type = 'table';
395
            $columns = array_keys($object) ?: [];
396
        }
397
398
        $result = self::get($tableName, true, ['id' => $id], true, ['*']);
399
        unset($result['id']);
400
401
        $data = [];
402
403 View Code Duplication
        if (!empty($extraFields) && isset($extraFields[$tableName])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
404
            $columns = array_merge($columns, $extraFields[$tableName]);
405
        }
406
407
        $flip = array_flip($columns);
408
        if ($type === 'object') {
409
            if ($object->getId()) {
410
                foreach ($result as $key => $value) {
411 View Code Duplication
                    if ($object->{'get'.ucfirst($flip[$key])}() !== $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
412
                        $data[$columns[$flip[$key]]] = $object->{'get'.ucfirst($flip[$key])}();
413
                    }
414
                }
415
            } else {
416
                foreach ($result as $key => $value) {
417
                    if ($object->{'get'.ucfirst($flip[$key])}() !== null) {
418 View Code Duplication
                        if ($object->{'get'.ucfirst($flip[$key])}() !== $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
419
                            $data[$columns[$flip[$key]]] = $object->{'get'.ucfirst($flip[$key])}();
420
                        }
421
                    }
422
                }
423
            }
424
        } else {
425
            foreach ($result as $key => $value) {
426
                if (isset($object[$key]) && $object[$key] !== $value) {
427
                    $data[$key] = $extraFields[$key];
428
                }
429
            }
430
431
        }
432
433
        if ($data) {
434
            $sql = "
435
                UPDATE
436
                    ".$tableName."
437
                SET
438
439
            ";
440
            foreach ($data as $key => $value) {
441
                $meta = self::$metadata[$tableName]->getFieldMapping($flip[$key]);
442
                $meta = $meta['type'];
443
                if (in_array($meta, [
444
                    'boolean',
445
                    'integer',
446
                    'longint',
447
                ])) {
448
                    $value = intval($value);
449
                } else {
450
                    $value = "'".addslashes(trim($value))."'";
451
                }
452
                $sql .= " ".$key." = ".$value.",";
453
            }
454
            $sql = substr($sql, 0, -1);
455
            $sql .= " WHERE id = ".$id;
456
            if ($out) {
457
                $out = $sql;
458
            }
459
460
            $sthu = self::$connection->prepare($sql);
461
            $sthu->execute();
462
        }
463
464
        self::close($noFkCheck);
465
    }
466
467
    public static function delete($object, $where = [], $noFkCheck = false, $manager = null, &$out = null)
468
    {
469
        self::init($noFkCheck, $manager);
470
        if (is_object($object)) {
471
            self::extract($object);
472
            $tableName = self::$tableName;
473
        } else {
474
            $tableName = $object;
475
        }
476
        $whereSql = self::buildWhere($tableName, $where);
477
        $sql = 'DELETE FROM '.$tableName.' '.$whereSql;
478
        if ($out) {
479
            $out = $sql;
480
        }
481
        $sth = self::$connection->prepare($sql);
482
        $sth->execute();
483
484
        self::close($noFkCheck);
485
    }
486
487
    public static function link($object, $data, $noFkCheck = false, $manager = null, &$out = null)
0 ignored issues
show
Coding Style introduced by
This method's name is shorter than the configured minimum length of 5 characters.

Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.

Loading history...
488
    {
489
        self::init($noFkCheck, $manager);
490
        if (is_object($object)) {
491
            self::extract($object);
492
            $tableName = self::$tableName;
493
        } else {
494
            $tableName = $object;
495
        }
496
        if ($object && $data) {
497
            $keys = $values = [];
498
            foreach ($data as $key => $value) {
499
                $keys[] = $key;
500
                $values[] = $value;
501
            }
502
            $sql = "
503
                INSERT IGNORE INTO
504
                    ".$tableName."
505
                        (".implode(',', $keys).")
506
                VALUES
507
                    (".implode(',', $values).")
508
            ";
509
            if ($out) {
510
                $out = $sql;
511
            }
512
            $sth = self::$connection->prepare($sql);
513
            $sth->execute();
514
        }
515
516
        self::close($noFkCheck);
517
    }
518
}
519