LanguageMenu   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 49
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLanguages() 0 4 1
A getLanguage() 0 4 1
A items() 0 17 2
A getSelectUrl() 0 12 2
1
<?php
2
/**
3
 * Yii2 module for language switching.
4
 *
5
 * @link      https://github.com/hiqdev/yii2-language
6
 * @package   yii2-language
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\language\menus;
12
13
use codemix\localeurls\UrlManager;
14
use Yii;
15
use yii\helpers\Url;
16
17
/**
18
 * Language Menu.
19
 *
20
 * @property Module $module The module to be used, can be found by default.
21
 */
22
class LanguageMenu extends \hiqdev\yii2\menus\Menu
23
{
24
    use \hiqdev\yii2\language\GetModuleTrait;
25
26
    public $widgetConfig = [
27
        'class' => \hiqdev\yii2\language\widgets\LanguageMenu::class,
28
    ];
29
30
    public function getLanguages()
31
    {
32
        return $this->getModule()->languages;
0 ignored issues
show
Bug introduced by
The property languages does not seem to exist. Did you mean _languages?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
33
    }
34
35
    public function getLanguage()
36
    {
37
        return Yii::$app->language;
38
    }
39
40
    public function items()
41
    {
42
        $url = $this->getSelectUrl();
43
        $language = $this->getLanguage();
44
        $items = [
45
            'language' => $language,
46
        ];
47
        foreach ($this->getLanguages() as $code => $lang) {
48
            $items[$code] = [
49
                'label'  => $lang,
50
                'url'    => Url::to(array_merge($url, ['language' => $code])),
51
                'active' => mb_stristr($language, $code),
52
            ];
53
        }
54
55
        return $items;
56
    }
57
58
    public function getSelectUrl()
59
    {
60
        if (Yii::$app->urlManager instanceof UrlManager) {
0 ignored issues
show
Bug introduced by
The class codemix\localeurls\UrlManager does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
61
            $route = Yii::$app->controller->route;
62
            $params = Yii::$app->request->get();
63
            array_unshift($params, '/' . $route);
64
65
            return $params;
66
        }
67
68
        return ['/' . $this->getModule()->id . '/language/select'];
69
    }
70
}
71