Completed
Push — master ( 184582...8b0917 )
by Razon
02:14
created

SiteController::actionLogout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace App\Http\Controller;
3
4
use App\Http\Form\ContactForm;
5
use App\Http\Form\LoginForm;
6
use Yii;
7
use yii\captcha\CaptchaAction;
8
use yii\web\ErrorAction;
9
10
class SiteController extends Controller
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function actions()
16
    {
17
        return [
18
            'error' => [
19
                'class' => ErrorAction::class,
20
            ],
21
            'captcha' => [
22
                'class' => CaptchaAction::class,
23
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
24
            ],
25
        ];
26
    }
27
28
    /**
29
     * Displays homepage.
30
     *
31
     * @return mixed
32
     */
33
    public function actionIndex()
34
    {
35
        return $this->render('index');
36
    }
37
38
    /**
39
     * Displays contact page.
40
     *
41
     * @return mixed
42
     */
43
    public function actionContact()
44
    {
45
        $model = new ContactForm();
46
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
47
            if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
48
                Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will get in touch with you as soon as possible.');
0 ignored issues
show
Bug introduced by
The method setFlash() does not exist on null. ( Ignorable by Annotation )

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

48
                Yii::$app->session->/** @scrutinizer ignore-call */ 
49
                                    setFlash('success', 'Thank you for contacting us. We will get in touch with you as soon as possible.');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
            } else {
50
                Yii::$app->session->setFlash('error', 'There was an error sending your message.');
51
            }
52
53
            return $this->refresh();
54
        }
55
56
        return $this->render('contact', [
57
            'model' => $model,
58
        ]);
59
    }
60
61
    /**
62
     * Displays about page.
63
     *
64
     * @return mixed
65
     */
66
    public function actionAbout()
67
    {
68
        return $this->render('about');
69
    }
70
71
    /**
72
     * Logs out the current user.
73
     *
74
     * @return mixed
75
     */
76
    public function actionLogin()
77
    {
78
        if (!Yii::$app->user->isGuest) {
79
            return $this->goHome();
80
        }
81
82
        $model = new LoginForm();
83
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
84
            return $this->goBack();
85
        }
86
87
        $model->password = '';
88
        return $this->render('login', [
89
            'model' => $model,
90
        ]);
91
    }
92
93
    /**
94
     * Logs out the current user.
95
     *
96
     * @return mixed
97
     */
98
    public function actionLogout()
99
    {
100
        Yii::$app->user->logout();
0 ignored issues
show
Bug introduced by
The method logout() does not exist on null. ( Ignorable by Annotation )

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

100
        Yii::$app->user->/** @scrutinizer ignore-call */ 
101
                         logout();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
101
102
        return $this->goHome();
103
    }
104
}
105