Passed
Push — master ( 922b86...f4cc02 )
by Koen
02:28
created

JoinTranslationScope   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 7
dl 0
loc 17
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 8 1
1
<?php declare(strict_types=1);
2
3
namespace KoenHoeijmakers\LaravelTranslatable\Scopes;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Scope;
8
use Illuminate\Database\Query\JoinClause;
9
10
class JoinTranslationScope implements Scope
11
{
12
    /**
13
     * Apply the scope to a given Eloquent query builder.
14
     *
15
     * @param  \Illuminate\Database\Eloquent\Builder                                                    $builder
16
     * @param  \Illuminate\Database\Eloquent\Model|\KoenHoeijmakers\LaravelTranslatable\HasTranslations $model
17
     * @return void
18
     */
19 6
    public function apply(Builder $builder, Model $model)
20
    {
21
        $builder->leftJoin($model->getTranslationTable(), function (JoinClause $join) use ($model) {
22 6
            $join->on(
23 6
                $model->getTable() . '.' . $model->getKeyName(),
24 6
                $model->getTranslationTable() . '.' . $model->getForeignKey()
0 ignored issues
show
Bug introduced by
Are you sure $model->getTranslationTable() of type Illuminate\Database\Eloquent\Builder|mixed can be used in concatenation? ( Ignorable by Annotation )

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

24
                /** @scrutinizer ignore-type */ $model->getTranslationTable() . '.' . $model->getForeignKey()
Loading history...
25 6
            )->where($model->getLocaleKeyName(), $model->getLocale());
0 ignored issues
show
Bug introduced by
It seems like $model->getLocaleKeyName() can also be of type Illuminate\Database\Eloquent\Builder; however, parameter $column of Illuminate\Database\Query\Builder::where() does only seem to accept Closure|array|string, maybe add an additional type check? ( Ignorable by Annotation )

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

25
            )->where(/** @scrutinizer ignore-type */ $model->getLocaleKeyName(), $model->getLocale());
Loading history...
26 6
        })->select($model->getTable() . '.*', ...$model->formatTranslatableColumnsForSelect());
27 6
    }
28
}
29