GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#45)
by
unknown
03:00
created

MultilingualTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 0 Features 1
Metric Value
wmc 6
c 8
b 0
f 1
lcom 1
cbo 1
dl 0
loc 45
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
with() 0 1 ?
A localized() 0 13 4
A multilingual() 0 8 2
1
<?php
2
namespace omgdef\multilingual;
3
4
use Yii;
5
use yii\db\ActiveQuery;
6
7
/**
8
 * Multilingual trait.
9
 * Modify ActiveRecord query for multilingual support
10
 */
11
trait MultilingualTrait
12
{
13
    /**
14
     * @var string the name of the lang field of the translation table. Default to 'language'.
15
     */
16
    public $languageField = 'language';
17
18
    /**
19
     * Scope for querying by languages
20
     * @param $language
21
     * @param $abridge
22
     * @return $this
23
     */
24 4
    public function localized($language = null, $abridge = true)
25
    {
26 4
        if (!$language)
27 4
            $language = Yii::$app->language;
28
29 4
        if (!isset($this->with['translations'])) {
30 4
            $this->with(['translation' => function ($query) use ($language, $abridge) {
31 3
                $query->where([$this->languageField => $abridge ? substr($language, 0, 2) : $language]);
32 4
            }]);
33 4
        }
34
35 4
        return $this;
36
    }
37
38
    /**
39
     * Scope for querying by all languages
40
     * @return $this
41
     */
42 6
    public function multilingual()
43
    {
44 6
        if (isset($this->with['translation'])) {
45 1
            unset($this->with['translation']);
46 1
        }
47 6
        $this->with('translations');
48 6
        return $this;
49
    }
50
51
    /**
52
     * @return \yii\db\ActiveQuery
53
     */
54
    abstract public function with();
55
}
56