Completed
Push — master ( ccb78a...088866 )
by Andrii
02:21
created

ContactAction::run()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 13
cp 0
rs 9.2
cc 4
eloc 9
nc 3
nop 0
crap 20
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\actions;
12
13
use hisite\models\ContactForm;
14
use Yii;
15
16
class ContactAction extends \yii\base\Action
17
{
18
    public $redirect = true;
19
20
    public $redirectUrl = '/';
21
22
    public $anchor = 'contact';
23
24
    public function run()
25
    {
26
        $model = new ContactForm();
27
        if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
28
            Yii::$app->session->setFlash('contactFormSubmitted');
29
30
            if ($this->redirect) {
31
                return $this->controller->redirect(['/', '#' => $this->anchor]);
0 ignored issues
show
Bug introduced by tofid
The method redirect does only exist in yii\web\Controller, but not in yii\base\Controller.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
32
            } else {
33
                return $this->controller->refresh('#' . $this->anchor);
0 ignored issues
show
Bug introduced by tofid
The method refresh does only exist in yii\web\Controller, but not in yii\base\Controller.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
34
            }
35
        }
36
37
        return $this->controller->render('contact', compact('model'));
38
    }
39
}
40