LanguageTrait   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 30
c 0
b 0
f 0
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 15 1
1
<?php
2
3
namespace app\traits;
4
5
use Yii;
6
use app\helpers\BaseHelper;
7
use Itstructure\AdminModule\models\Language;
8
use Itstructure\AdminModule\components\AdminView;
9
10
/**
11
 * Class LanguageTrait
12
 *
13
 * @property AdminView $view
14
 * @property string $shortLanguage
15
 * @property Language[] $languages
16
 *
17
 * @package app\traits
18
 */
19
trait LanguageTrait
20
{
21
    /**
22
     * @var string
23
     */
24
    public $shortLanguage;
25
26
    /**
27
     * @var Language[]
28
     */
29
    public $languages;
30
31
    /**
32
     * Initialize.
33
     */
34
    public function init()
35
    {
36
        $this->shortLanguage = Yii::$app->request->get('shortLanguage');
0 ignored issues
show
Documentation Bug introduced by
It seems like Yii::app->request->get('shortLanguage') can also be of type array. However, the property $shortLanguage is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
37
38
        BaseHelper::setAppLanguage($this->shortLanguage);
0 ignored issues
show
Bug introduced by
It seems like $this->shortLanguage can also be of type array; however, parameter $shortLanguage of app\helpers\BaseHelper::setAppLanguage() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        BaseHelper::setAppLanguage(/** @scrutinizer ignore-type */ $this->shortLanguage);
Loading history...
39
40
        $this->languages = Language::find()->where([
41
            '!=', 'shortName', $this->shortLanguage
42
        ])->all();
43
44
        $this->view->params['languages'] = $this->languages;
45
46
        $this->view->params['shortLanguage'] = $this->shortLanguage;
47
48
        parent::init();
49
    }
50
}
51