Passed
Push — master ( af745e...ec06c1 )
by Koen
02:49
created

JoinTranslationScope::formatTranslatableColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
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
    public function apply(Builder $builder, Model $model)
20
    {
21
        $builder->leftJoin($model->getTranslationTable(), function (JoinClause $join) use ($model) {
22
            $join->on(
23
                $model->getTable() . '.' . $model->getKeyName(),
24
                $model->getTranslationTable() . '.' . $model->getForeignKey()
0 ignored issues
show
Bug introduced by
Are you sure $model->getTranslationTable() of type mixed|Illuminate\Database\Eloquent\Builder 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
            )->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 string|Closure|array, 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
        })->select($model->getTable() . '.*', ...$model->formatTranslatableColumnsForSelect());
27
    }
28
}
29