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

BatchInsertCommandTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A batchInsertIgnoreCommand() 0 7 1
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
}