Completed
Push — master ( 2020fc...c686ed )
by Michael
06:11
created

InsertTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A scopeInsertSelect() 0 11 2
1
<?php
2
3
namespace App\Http\Traits;
4
5
use Blasttech\EloquentRelatedPlus\HelpersTrait;
6
use Illuminate\Database\Eloquent\Builder;
7
8
/**
9
 * Trait InsertSelect
10
 * @package App\Http\Traits
11
 *
12
 * @method bool insertSelect(Builder $builder, array $insertColumns = [])
13
 */
14
trait InsertTrait
15
{
16
    use HelpersTrait;
17
18
    /**
19
     * InsertSelect - builds SQL for 'INSERT INTO tablename (field1, field2) FROM SELECT a1, a2 FROM table2'
20
     *
21
     * @param Builder $query - the Builder to insert into
22
     * @param Builder $builder - the Query Builder to select from
23
     * @param array $insertColumns - the columns to insert into
24
     * @return bool
25
     */
26
    public function scopeInsertSelect(Builder $query, Builder $builder, array $insertColumns = [])
27
    {
28
        $insert = 'INSERT INTO ' . $query->getModel()->getTable();
29
30
        if (!empty($insertColumns)) {
31
            $insert .= ' (' . implode(', ', $insertColumns) . ')';
32
        }
33
34
        $insert .= ' ' . $this->toSqlWithBindings($builder);
35
36
        return $query->getConnection()->statement($insert);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->getConnec...n()->statement($insert) also could return the type Illuminate\Database\Eloq...ase\ConnectionInterface which is incompatible with the documented return type boolean.
Loading history...
37
    }
38
}
39