Passed
Push — master ( c686ed...3db3c3 )
by Michael
01:57
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 Blasttech\EloquentRelatedPlus;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
/**
8
 * Trait InsertSelect
9
 * @package App\Http\Traits
10
 *
11
 * @method bool insertSelect(Builder $builder, array $insertColumns = [])
12
 */
13
trait InsertTrait
14
{
15
    use HelpersTrait;
16
17
    /**
18
     * InsertSelect - builds SQL for 'INSERT INTO tablename (field1, field2) FROM SELECT a1, a2 FROM table2'
19
     *
20
     * @param Builder $query - the Builder to insert into
21
     * @param Builder $builder - the Query Builder to select from
22
     * @param array $insertColumns - the columns to insert into
23
     * @return bool
24
     */
25
    public function scopeInsertSelect(Builder $query, Builder $builder, array $insertColumns = [])
26
    {
27
        $insert = 'INSERT INTO ' . $query->getModel()->getTable();
28
29
        if (!empty($insertColumns)) {
30
            $insert .= ' (' . implode(', ', $insertColumns) . ')';
31
        }
32
33
        $insert .= ' ' . $this->toSqlWithBindings($builder);
34
35
        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...
36
    }
37
}
38