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

IsPostgresRelation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 36
ccs 9
cts 9
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonColumn() 0 13 5
A whereInMethod() 0 3 1
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