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.

MultilingualTrait::multilingual()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 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
 * @mixin ActiveQuery
12
 */
13
trait MultilingualTrait
14
{
15
    /**
16
     * @var string the name of the lang field of the translation table. Default to 'language'.
17
     */
18
    public $languageField = 'language';
19
20
    /**
21
     * Scope for querying by languages
22
     *
23
     * @param string $language
24
     * @param bool   $abridge
25
     *
26
     * @return $this
27
     */
28 4
    public function localized($language = null, $abridge = true)
29
    {
30 4
        $language = $language ?: Yii::$app->language;
31
32 4
        if (!isset($this->with['translations'])) {
33 4
            $this->with(['translation' => function ($query) use ($language, $abridge) {
0 ignored issues
show
Bug introduced by
It seems like with() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34
                /** @var ActiveQuery $query */
35 3
                $query->where([$this->languageField => $abridge ? substr($language, 0, 2) : $language]);
36 4
            }]);
37 4
        }
38
39 4
        return $this;
40
    }
41
42
    /**
43
     * Scope for querying by all languages
44
     * @return $this
45
     */
46 6
    public function multilingual()
47
    {
48 6
        if (isset($this->with['translation'])) {
49 1
            unset($this->with['translation']);
50 1
        }
51 6
        $this->with('translations');
0 ignored issues
show
Bug introduced by
It seems like with() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
52 6
        return $this;
53
    }
54
}
55