HasLanguage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeByLang() 0 11 4
A getLangcodeColumn() 0 3 1
1
<?php
2
3
namespace Fomvasss\LaravelTranslatable\Traits;
4
5
use Illuminate\Support\Facades\App;
6
7
trait HasLanguage
8
{
9
    /**
10
     * @return string
11
     */
12
    public function getLangcodeColumn(): string
13
    {
14
        return config('translatable.db.columns.langcode');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

14
        return /** @scrutinizer ignore-call */ config('translatable.db.columns.langcode');
Loading history...
15
    }
16
17
    /**
18
     * @param $query
19
     * @param null|string|array $langcode
20
     * @return mixed
21
     */
22
    public function scopeByLang($query, $langcode = null)
23
    {
24
        $langcode = $langcode ?: App::getLocale();
25
26
        if (is_array($langcode) && count($langcode)) {
27
            return $query->whereIn($this->getLangcodeColumn(), $langcode)
28
                ->orWhereNull($this->getLangcodeColumn());
29
        }
30
31
        $query->where($this->getLangcodeColumn(), $langcode)
32
            ->orWhereNull($this->getLangcodeColumn());
33
    }
34
}