Localable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A scopeLocale() 0 8 3
1
<?php
2
3
namespace Distilleries\Contentful\Models\Traits;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Distilleries\Contentful\Models\Locale;
7
8
trait Localable
9
{
10
    abstract public function getTable();
11
12
    /**
13
     * Scope a query to a given locale.
14
     *
15
     * @param  \Illuminate\Database\Eloquent\Builder  $query
16
     * @param  string|null  $locale
17
     * @param  string|null  $country
18
     * @return \Illuminate\Database\Eloquent\Builder
19
     */
20
    public function scopeLocale($query, ?string $locale = '', ?string $country = ''): Builder
21
    {
22
        $locale = ! empty($locale) ? $locale : Locale::getAppOrDefaultLocale();
23
        $country = ! empty($country) ? $country : Locale::getAppOrDefaultCountry();
24
25
        return $query
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->whereRaw(...ER("' . $locale . '")') could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
26
            ->whereRaw('LOWER(' . $this->getTable() . '.country) LIKE LOWER("' . $country . '")')
27
            ->whereRaw('LOWER(' . $this->getTable() . '.locale) LIKE LOWER("' . $locale . '")');
28
    }
29
}
30