Conditions | 11 |
Paths | 18 |
Total Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
66 | public function computeViewFile($model, $defaultView = '') |
||
67 | { |
||
68 | if (Yii::$app->response->view_id !== null) { |
||
69 | $view = \app\models\View::getViewById(Yii::$app->response->view_id); |
||
70 | if (!is_null($view)) { |
||
71 | if ($view === 'default') { |
||
72 | $view = ViewObject::getViewByModel($model->parent); |
||
73 | } |
||
74 | return $view === null ? $defaultView : $view; |
||
75 | } |
||
76 | } |
||
77 | if (is_null($model)) { |
||
78 | return $defaultView; |
||
79 | } |
||
80 | |||
81 | do { |
||
82 | $view = ViewObject::getViewByModel($model); |
||
83 | if (is_null($view) || $view == 'default') { |
||
84 | $view = ViewObject::getViewByModel($model->parent, true); |
||
85 | } |
||
86 | if (!is_null($view)) { |
||
87 | return $view === 'default' ? $defaultView : $view; |
||
88 | } |
||
89 | $model = $model->parent; |
||
90 | } while (!is_null($model)); |
||
91 | |||
92 | return $defaultView; |
||
93 | } |
||
94 | |||
111 |
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: