Passed
Push — master ( 7ba57e...634515 )
by Paweł
03:13
created

batchInsertIgnoreCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 2019-02-12
6
 */
7
8
namespace app\components\traits;
9
10
11
12
use Yii;
13
14
trait BatchInsertCommandTrait
15
{
16
    /**
17
     * @param string $table
18
     * @param array $columns
19
     * @param array $rows
20
     * @return \yii\db\Command
21
     */
22
    public function batchInsertIgnoreCommand(string $table, array $columns, array $rows)
23
    {
24
        $sql = Yii::$app->db->queryBuilder
25
            ->batchInsert($table, $columns, $rows);
26
        $sql = str_replace('INSERT INTO ', 'INSERT IGNORE INTO ', $sql);
27
28
        return Yii::$app->db->createCommand($sql);
29
    }
30
}