Completed
Push — master ( 825d81...9c7056 )
by Maxime
08:49
created

Localable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A scopeLocale() 0 9 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: mfrancois
5
 * Date: 12/07/2018
6
 * Time: 15:30
7
 */
8
9
namespace Distilleries\Contentful\Models\Traits;
10
11
12
use Illuminate\Database\Eloquent\Builder;
13
14
trait Localable
15
{
16
    // --------------------------------------------------------------------------------
17
    // --------------------------------------------------------------------------------
18
    // --------------------------------------------------------------------------------
19
20
    /**
21
     * Scope a query to a given locale.
22
     *
23
     * @param  \Illuminate\Database\Eloquent\Builder  $query
24
     * @param  string  $locale
25
     * @param  string  $country
26
     * @return \Illuminate\Database\Eloquent\Builder
27
     */
28
    public function scopeLocale($query, string $locale = '',string $country='') : Builder
29
    {
30
        $locale = ! empty($locale) ? $locale : Locale::getAppOrDefaultLocale();
31
        $country = ! empty($country) ? $country : Locale::getAppOrDefaultCountry();
32
33
        return $query
34
            ->whereRaw('LOWER(country) LIKE LOWER("' . $country . '")')
35
            ->whereRaw('LOWER(locale) LIKE LOWER("' . $locale . '")');
36
    }
37
38
}