ErrorController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 33
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A actions() 0 6 1
A actionSend() 0 17 3
A actionTest() 0 5 1
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
Bug introduced by
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