JoinTranslationScope   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KoenHoeijmakers\LaravelTranslatable\Scopes;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Database\Eloquent\Model;
9
use Illuminate\Database\Eloquent\Scope;
10
use Illuminate\Database\Query\JoinClause;
11
12
class JoinTranslationScope implements Scope
13
{
14
    /**
15
     * Apply the scope to a given Eloquent query builder.
16
     *
17
     * @param  \Illuminate\Database\Eloquent\Builder                                                    $builder
18
     * @param  \Illuminate\Database\Eloquent\Model|\KoenHoeijmakers\LaravelTranslatable\HasTranslations $model
19
     * @return void
20
     */
21 24
    public function apply(Builder $builder, Model $model)
22
    {
23
        $builder->leftJoin($model->getTranslationTable(), function (JoinClause $join) use ($model) {
24 24
            $join->on(
25 24
                $model->getTable() . '.' . $model->getKeyName(),
26 24
                $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

26
                /** @scrutinizer ignore-type */ $model->getTranslationTable() . '.' . $model->getForeignKey()
Loading history...
27 24
            )->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

27
            )->where(/** @scrutinizer ignore-type */ $model->getLocaleKeyName(), $model->getLocale());
Loading history...
28 24
        })->addSelect($model->getTable() . '.*', ...$model->formatTranslatableColumnsForSelect());
29 24
    }
30
}
31