| Conditions | 18 |
| Paths | 18 |
| Total Lines | 47 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 156 | public function __call($method, $args = []) |
||
| 157 | { |
||
| 158 | $model = models($this->model->getClass()); |
||
| 159 | |||
| 160 | if (method_exists($model, $method)) { |
||
| 161 | $model->row = $this; |
||
| 162 | |||
| 163 | if (false !== ($result = call_user_func_array([&$model, $method], $args))) { |
||
| 164 | $this->offsetSet($method, $result); |
||
| 165 | |||
| 166 | return $result; |
||
| 167 | } |
||
| 168 | } elseif (strpos($method, 'Url')) { |
||
| 169 | $key = str_replace('Url', '', $method); |
||
| 170 | |||
| 171 | if ($key === $model->uploadedImageKey) { |
||
| 172 | if (isset($model->uploadedImageFilePath)) { |
||
| 173 | if (is_file($filePath = $model->uploadedImageFilePath . $this->offsetGet($key))) { |
||
| 174 | return images_url($filePath); |
||
| 175 | } elseif (is_file($filePath = PATH_STORAGE . 'images/default/not-found.jpg')) { |
||
| 176 | return images_url($filePath); |
||
| 177 | } elseif (is_file($filePath = PATH_STORAGE . 'images/default/not-found.png')) { |
||
| 178 | return images_url($filePath); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } elseif (in_array($key, $model->uploadedImageKeys)) { |
||
| 182 | if (isset($model->uploadedImageFilePath)) { |
||
| 183 | if (is_file($filePath = $model->uploadedImageFilePath . $this->offsetGet($key))) { |
||
| 184 | return images_url($filePath); |
||
| 185 | } elseif (is_file($filePath = PATH_STORAGE . 'images/default/not-found.jpg')) { |
||
| 186 | return images_url($filePath); |
||
| 187 | } elseif (is_file($filePath = PATH_STORAGE . 'images/default/not-found.png')) { |
||
| 188 | return images_url($filePath); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } elseif ($key === $model->uploadedFileKey) { |
||
| 192 | if (isset($model->uploadedFileFilepath)) { |
||
| 193 | return storage_url($model->uploadedFileFilepath . $this->offsetGet($key)); |
||
| 194 | } |
||
| 195 | } elseif (in_array($key, $model->uploadedFileKeys)) { |
||
| 196 | if (isset($model->uploadedFileFilepath)) { |
||
| 197 | return storage_url($model->uploadedFileFilepath . $this->offsetGet($key)); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } |
||
| 201 | |||
| 202 | return null; |
||
| 203 | } |
||
| 235 | } |