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::localized()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.2
cc 4
eloc 7
nc 4
nop 2
crap 4
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