SiteController   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 4
dl 0
loc 93
c 0
b 0
f 0
ccs 0
cts 61
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A actions() 0 29 2
A actionLogin() 0 13 4
A actionLogout() 0 7 3
A actionContact() 0 11 3
A actionTransition() 0 6 1
1
<?php
2
/**
3
 * HiSite Yii2 base project.
4
 *
5
 * @link      https://github.com/hiqdev/hisite
6
 * @package   hisite
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hisite\controllers;
12
13
use hisite\actions\ContactAction;
14
use hisite\actions\RenderAction;
15
use hisite\models\ContactForm;
16
use hisite\models\LoginForm;
17
use Yii;
18
use yii\captcha\CaptchaAction;
19
use yii\web\ErrorAction;
20
21
class SiteController extends \yii\web\Controller
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function actions()
27
    {
28
        return [
29
            'error' => [
30
                'class' => ErrorAction::class,
31
            ],
32
            'captcha' => [
33
                'class' => CaptchaAction::class,
34
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
35
                'backColor' => 0x222222,
36
                'foreColor' => 0xFFFFFF,
37
            ],
38
            'index' => [
39
                'class' => RenderAction::class,
40
                'data' => function () {
41
                    return ['contactForm' => new ContactForm()];
42
                },
43
            ],
44
            'about' => [
45
                'class' => RenderAction::class,
46
            ],
47
            'policy' => [
48
                'class' => RenderAction::class,
49
            ],
50
            'contact' => [
51
                'class' => ContactAction::class,
52
            ],
53
        ];
54
    }
55
56
    /**
57
     * Login action.
58
     * @return string
59
     */
60
    public function actionLogin()
61
    {
62
        if (!Yii::$app->user->isGuest) {
63
            return $this->goHome();
64
        }
65
66
        $model = new LoginForm();
67
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
68
            return $this->goBack();
69
        }
70
71
        return $this->render('login', compact('model'));
72
    }
73
74
    /**
75
     * Logout action.
76
     * @return string
77
     */
78
    public function actionLogout()
79
    {
80
        Yii::$app->user->logout();
81
        $back = Yii::$app->request->post('back') ?: Yii::$app->request->get('back');
82
83
        return $back ? $this->redirect($back) : $this->goHome();
84
    }
85
86
    /**
87
     * Displays contact page and sends contact form.
88
     * @return string
89
     */
90
    public function actionContact()
91
    {
92
        $model = new ContactForm();
93
        if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
94
            Yii::$app->session->setFlash('contactFormSubmitted');
95
96
            return $this->refresh();
97
        }
98
99
        return $this->render('contact', compact('model'));
100
    }
101
102
    /**
103
     * Action of redirect to admin panel after data submit
104
     *
105
     * @return string
106
     */
107
    public function actionTransition()
108
    {
109
        return $this->render('transition', [
110
            'href' => 'back',
111
        ]);
112
    }
113
}
114