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.

PropertyHandler   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 29.09 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 6
dl 16
loc 55
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 16 16 4
A run() 0 23 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace app\backend\actions;
4
5
use app\models\BaseObject;
6
use app\models\Property;
7
use app\properties\PropertyHandlers;
8
use yii;
9
use yii\base\Action;
10
11
class PropertyHandler extends Action
12
{
13
    public $modelName = null;
14
    public $objectId = null;
15
16
    /**
17
     * @throws yii\web\ServerErrorHttpException
18
     */
19 View Code Duplication
    public function init()
20
    {
21
        parent::init();
22
        if (null === $this->modelName) {
23
            throw new yii\web\ServerErrorHttpException('Model name should be set in controller actions');
24
        }
25
26
        if (!is_subclass_of($this->modelName, '\yii\db\ActiveRecord')) {
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...
27
            throw new yii\web\ServerErrorHttpException('Model class does not exists');
28
        }
29
30
        $this->objectId = BaseObject::getForClass($this->modelName);
31
        if (null === $this->objectId) {
32
            throw new yii\web\ServerErrorHttpException('Object does not exists for model.');
33
        }
34
    }
35
36
    /**
37
     * @param null $property_id
38
     * @param null $handler_action
39
     * @param null $model_id
40
     * @return mixed
41
     */
42
    public function run($property_id = null, $handler_action = null, $model_id = null)
43
    {
44
        if (null === $handler_action
45
            || null === $property_id
46
            || null === $model_id)
47
        {
48
            return '';
49
        }
50
51
        $property = Property::findById($property_id);
52
        if (null === $property) {
53
            return '';
54
        }
55
56
        $actionParams = [
57
            'model_name' => $this->modelName,
58
            'model_id' => $model_id,
59
            'object_id' => $this->objectId,
60
            'property' => $property,
61
        ];
62
        $propertyHandler = PropertyHandlers::createHandler($property->handler);
0 ignored issues
show
Bug introduced by
The property handler does not seem to exist. Did you mean handlerAdditionalParams?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
63
        return $propertyHandler->runAction($handler_action, $actionParams);
64
    }
65
}
66