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   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 10
Bugs 0 Features 1
Metric Value
wmc 6
c 10
b 0
f 1
lcom 1
cbo 2
dl 0
loc 42
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
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
 * @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