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

RedirectController::actionHomePage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
nc 3
nop 0
dl 0
loc 16
c 0
b 0
f 0
cc 3
rs 9.9666
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