Completed
Pull Request — master (#171)
by Corey
04:56
created

Controller   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 15
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actions() 0 8 1
A beforeAction() 0 16 6
1
<?php
2
3
namespace common\components;
4
5
use Yii;
6
7
class Controller extends \yii\web\Controller {
8
  /**
9
   * {@inheritdoc}
10
   */
11
  public function beforeAction($action)
12
  {
13
    if ($this->enableCsrfValidation
14
      && Yii::$app->getErrorHandler()->exception === null
15
      && !Yii::$app->getRequest()->validateCsrfToken()) {
16
17
      Yii::$app->session->setFlash('error', 'Your security token has expired. Please retry your submission.');
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

17
      Yii::$app->session->/** @scrutinizer ignore-call */ 
18
                          setFlash('error', 'Your security token has expired. Please retry your submission.');

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...
18
      $this->redirect(Yii::$app->request->referrer ?: Yii::$app->homeUrl);
0 ignored issues
show
Bug introduced by
It seems like Yii::app->request->referrer ?: Yii::app->homeUrl can also be of type object; however, parameter $url of yii\web\Controller::redirect() does only seem to accept array|string, 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

18
      $this->redirect(/** @scrutinizer ignore-type */ Yii::$app->request->referrer ?: Yii::$app->homeUrl);
Loading history...
19
      return false;
20
    }
21
22
    if(!parent::beforeAction($action)) {
23
      return false;
24
    }
25
26
    return true;
27
  }
28
29
  /**
30
   * @inheritdoc
31
   */
32
  public function actions()
33
  {
34
    return [
35
      'error' => [
36
         'class' => 'yii\web\ErrorAction',
37
       ],
38
      'captcha' => [
39
        'class' => 'yii\captcha\CaptchaAction',
40
      ],
41
    ];
42
  }
43
}