SubscribeAction   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 5
1
<?php
2
3
namespace dominus77\maintenance\actions\frontend;
4
5
use Yii;
6
use yii\base\Action;
7
use yii\web\Response;
8
use yii\web\Session;
9
use dominus77\maintenance\models\SubscribeForm;
10
use dominus77\maintenance\BackendMaintenance;
11
12
/**
13
 * Class SubscribeAction
14
 * @package dominus77\maintenance\actions\frontend
15
 */
16
class SubscribeAction extends Action
17
{
18
    /**
19
     * @return Response
20
     */
21
    public function run()
22
    {
23
        $model = new SubscribeForm();
24
        $msgSuccess = BackendMaintenance::t('app', 'We will inform you when everything is ready!');
25
        $msgInfo = BackendMaintenance::t('app', 'You have already subscribed to the alert!');
26
        if (($post = Yii::$app->request->post()) && $model->load($post) && $model->validate()) {
0 ignored issues
show
Bug introduced by
It seems like $post can also be of type object; however, parameter $data of yii\base\Model::load() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

26
        if (($post = Yii::$app->request->post()) && $model->load(/** @scrutinizer ignore-type */ $post) && $model->validate()) {
Loading history...
27
            /** @var Session $session */
28
            $session = Yii::$app->session;
29
            if ($model->subscribe()) {
30
                $session->setFlash($model::SUBSCRIBE_SUCCESS, $msgSuccess);
31
            } else {
32
                $session->setFlash($model::SUBSCRIBE_INFO, $msgInfo);
33
            }
34
        }
35
        return $this->controller->redirect(Yii::$app->request->referrer);
36
    }
37
}
38