Passed
Push — master ( 2ebb51...c237bf )
by Jonas
05:46
created

IsPostgresRelation::whereInMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Staudenmeir\EloquentJsonRelations\Relations\Postgres;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Query\Expression;
8
9
trait IsPostgresRelation
10
{
11
    /**
12
     * Get the wrapped and cast JSON column.
13
     *
14
     * @param \Illuminate\Database\Eloquent\Builder $query
15
     * @param \Illuminate\Database\Eloquent\Model $model
16
     * @param string $column
17
     * @param string $key
18
     * @return \Illuminate\Database\Query\Expression
19
     */
20 20
    protected function jsonColumn(Builder $query, Model $model, $column, $key)
21
    {
22 20
        $sql = $query->getQuery()->getGrammar()->wrap($column);
23
24 20
        if ($model->getKeyName() === $key && in_array($model->getKeyType(), ['int', 'integer'])) {
25 18
            $sql = '('.$sql.')::int';
26
        }
27
28 20
        if ($model->hasCast($key) && $model->getCasts()[$key] === 'uuid') {
29 2
            $sql = '('.$sql.')::uuid';
30
        }
31
32 20
        return new Expression($sql);
33
    }
34
35
    /**
36
     * Get the name of the "where in" method for eager loading.
37
     *
38
     * @param \Illuminate\Database\Eloquent\Model $model
39
     * @param string $key
40
     * @return string
41
     */
42 14
    protected function whereInMethod(Model $model, $key)
0 ignored issues
show
Unused Code introduced by
The parameter $key 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

42
    protected function whereInMethod(Model $model, /** @scrutinizer ignore-unused */ $key)

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...
Unused Code introduced by
The parameter $model 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

42
    protected function whereInMethod(/** @scrutinizer ignore-unused */ Model $model, $key)

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...
43
    {
44 14
        return 'whereIn';
45
    }
46
}
47