CompilesUpsertQueries   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compileUpsert() 0 13 2
A compileInsertIgnore() 0 3 1
1
<?php
2
3
namespace Staudenmeir\LaravelUpsert\Query\Grammars;
4
5
use Illuminate\Database\Query\Builder;
6
7
trait CompilesUpsertQueries
8
{
9
    /**
10
     * Compile an "upsert" statement into SQL.
11
     *
12
     * @param \Illuminate\Database\Query\Builder $query
13
     * @param array $values
14
     * @param array $target
15
     * @param array $update
16
     * @return string
17
     */
18 16
    public function compileUpsert(Builder $query, array $values, array $target, array $update)
19
    {
20 16
        $sql = $this->compileInsert($query, $values);
0 ignored issues
show
Bug introduced by
The method compileInsert() does not exist on Staudenmeir\LaravelUpser...s\CompilesUpsertQueries. Did you maybe mean compileInsertIgnore()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        /** @scrutinizer ignore-call */ 
21
        $sql = $this->compileInsert($query, $values);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
22 16
        $sql .= ' on conflict ('.$this->columnize($target).') do update set ';
0 ignored issues
show
Bug introduced by
It seems like columnize() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $sql .= ' on conflict ('.$this->/** @scrutinizer ignore-call */ columnize($target).') do update set ';
Loading history...
23
24 16
        $columns = collect($update)->map(function ($value, $key) {
25 16
            return is_numeric($key)
26 14
                ? $this->wrap($value).' = '.$this->wrapValue('excluded').'.'.$this->wrap($value)
0 ignored issues
show
Bug introduced by
It seems like wrapValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
                ? $this->wrap($value).' = '.$this->/** @scrutinizer ignore-call */ wrapValue('excluded').'.'.$this->wrap($value)
Loading history...
Bug introduced by
It seems like wrap() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
                ? $this->/** @scrutinizer ignore-call */ wrap($value).' = '.$this->wrapValue('excluded').'.'.$this->wrap($value)
Loading history...
27 16
                : $this->wrap($key).' = '.$this->parameter($value);
0 ignored issues
show
Bug introduced by
It seems like parameter() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
                : $this->wrap($key).' = '.$this->/** @scrutinizer ignore-call */ parameter($value);
Loading history...
28 16
        })->implode(', ');
29
30 16
        return $sql.$columns;
31
    }
32
33
    /**
34
     * Compile an "insert ignore" statement into SQL.
35
     *
36
     * @param \Illuminate\Database\Query\Builder $query
37
     * @param array $values
38
     * @param array $target
39
     * @return string
40
     */
41 8
    public function compileInsertIgnore(Builder $query, array $values, array $target)
0 ignored issues
show
Unused Code introduced by
The parameter $target is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

41
    public function compileInsertIgnore(Builder $query, array $values, /** @scrutinizer ignore-unused */ array $target)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43 8
        return $this->compileInsert($query, $values).' on conflict do nothing';
44
    }
45
}
46