Passed
Pull Request — master (#1)
by
unknown
05:25
created

RedirectController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionHomePage() 0 16 3
1
<?php
2
3
namespace app\controllers;
4
5
use Yii;
6
use yii\web\Controller;
7
use Itstructure\AdminModule\models\Language;
8
use app\helpers\BaseHelper;
9
10
/**
11
 * Class RedirectController
12
 *
13
 * @package app\controllers
14
 */
15
class RedirectController extends Controller
16
{
17
    /**
18
     * Redirect to home page with default language.
19
     */
20
    public function actionHomePage()
21
    {
22
        $clientShortLanguage = BaseHelper::detectClientShortLanguage();
23
24
        if (null === $clientShortLanguage) {
25
            $shortLanguage = Language::getDefaultLanguage()->shortName;
26
27
        } else {
28
            $check = Language::find()->where([
29
                'shortName' => $clientShortLanguage
30
            ])->count();
31
32
            $shortLanguage = $check == 0 ? Language::getDefaultLanguage()->shortName : $clientShortLanguage;
33
        }
34
35
        Yii::$app->response->redirect('/'.$shortLanguage, 302)->send();
36
    }
37
}
38