GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AbstractHandler::render()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 5
1
<?php
2
3
namespace app\properties\handlers;
4
5
abstract class AbstractHandler
6
{
7
    /** @var \app\models\PropertyHandler $propertyHandler */
8
    protected $propertyHandler;
9
    /** @var \yii\base\Widget $widgetClass */
10
    protected $widgetClass = null;
11
    protected $additionalRenderData = [];
12
13
    /**
14
     * @param \app\models\PropertyHandler $propertyHandler
15
     */
16
    function __construct(\app\models\PropertyHandler $propertyHandler)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
17
    {
18
        $this->propertyHandler = $propertyHandler;
19
20
        $widgetClass = !empty($this->widgetClass) ? $this->widgetClass : get_called_class().'Widget';
21
        if (class_exists($widgetClass) && is_subclass_of($widgetClass, '\app\properties\handlers\AbstractHandlerWidget')) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
22
            $this->widgetClass = $widgetClass;
0 ignored issues
show
Documentation Bug introduced by
It seems like $widgetClass can also be of type string. However, the property $widgetClass is declared as type object<yii\base\Widget>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
23
        } else {
24
            $this->widgetClass = null;
25
        }
26
27
        $this->init();
28
    }
29
30
    /**
31
     * Initialize instance
32
     */
33
    public function init()
34
    {
35
    }
36
37
    /**
38
     * @param \app\models\Property $property
39
     * @return bool
40
     */
41
    public function changePropertyType(\app\models\Property &$property)
42
    {
43
        return false;
44
    }
45
46
    /**
47
     * @param $property
48
     * @param $model
49
     * @param $values
50
     * @param $form
51
     * @param $renderType
52
     * @return string
53
     */
54
    public function render($property, $model, $values, $form, $renderType)
55
    {
56
        if (!empty($this->widgetClass)) {
57
            $widgetClass = $this->widgetClass;
58
            $renderType = isset($this->propertyHandler->$renderType) ? $this->propertyHandler->$renderType : $this->propertyHandler->frontend_render_view;
59
            return $widgetClass::widget([
60
                'values' => $values,
61
                'form' => $form,
62
                'model' => $model,
63
                'property_key' => $property->key,
64
                'property_id' => $property->id,
65
                'label' => $property->name,
66
                'multiple' => $property->multiple,
67
                'viewFile' => $renderType,
68
                'additional' => $this->additionalRenderData,
69
            ]);
70
        }
71
72
        return '';
73
    }
74
75
    /**
76
     * @param \app\models\Property $property
77
     * @param string $formProperties
78
     * @param array $values
79
     * @return array
80
     */
81
    public function processValues(\app\models\Property $property, $formProperties = '', $values = [])
82
    {
83
        return $values;
84
    }
85
86
    /**
87
     * @param string|null $action Method of handler
88
     * @param array $params
89
     * @return mixed|string
90
     */
91
    public function runAction($action = null, $params = [])
92
    {
93
        if (preg_match('#^[a-z0-9\\-_]+$#', $action) && strpos($action, '--') === false && trim($action, '-') === $action) {
94
            $methodName = 'action' . str_replace(' ', '', ucwords(implode(' ', explode('-', $action))));
95
            if (method_exists($this, $methodName)) {
96
                $method = new \ReflectionMethod($this, $methodName);
97
                if ($method->isPublic() && $method->getName() === $methodName) {
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
98
                    return call_user_func([$this, $methodName], $params);
99
                }
100
            }
101
        }
102
103
        return '';
104
    }
105
}
106
?>