Completed
Push — master ( 028ee3...a146dd )
by Andrii
21:15 queued 14:50
created

src/controllers/ErrorController.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Health monitoring for Yii2 applications
4
 *
5
 * @link      https://github.com/hiqdev/yii2-monitoring
6
 * @package   yii2-monitoring
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\monitoring\controllers;
12
13
use hiqdev\yii2\monitoring\actions\ErrorAction;
14
use hiqdev\yii2\monitoring\logic\DebugSessionSaver;
15
use hiqdev\yii2\monitoring\logic\FeedbackSender;
16
use hiqdev\yii2\monitoring\models\FeedbackForm;
17
use Yii;
18
use yii\web\Controller;
19
20
class ErrorController extends Controller
21
{
22
    public function actions()
23
    {
24
        return [
25
            'index' => ErrorAction::class,
26
        ];
27
    }
28
29
    public function actionSend()
30
    {
31
        $form = new FeedbackForm();
32
33
        if ($form->load(Yii::$app->request->post()) && $form->validate()) {
34
            /** @var FeedbackSender $sender */
35
            Yii::createObject(DebugSessionSaver::class, [$form->session_tag])->run();
36
            $sender = Yii::createObject(FeedbackSender::class, [$form]);
37
38
            return $this->render('sent', [
39
                'model' => $form,
40
                'success' => $sender->send(),
41
            ]);
42
        }
43
44
        return $this->redirect(Yii::$app->getHomeUrl());
0 ignored issues
show
The method getHomeUrl does only exist in yii\web\Application, but not in yii\console\Application.

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...
45
    }
46
47
    public function actionTest()
48
    {
49
        Yii::error('testing error');
50
        throw new \Exception('testing exception');
51
    }
52
}
53