Complex classes like BaseModelController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BaseModelController, and based on these observations, apply Extract Interface, too.
| 1 | <?php namespace Mascame\Artificer\Http\Controllers; |
||
| 19 | class BaseModelController extends BaseController |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The Eloquent model instance |
||
| 24 | * @var \Eloquent |
||
| 25 | */ |
||
| 26 | protected $model; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * |
||
| 30 | */ |
||
| 31 | public function __construct() |
||
| 32 | { |
||
| 33 | parent::__construct(); |
||
| 34 | |||
| 35 | if (! Auth::check() || ! ModelPermit::access()) { |
||
| 36 | App::abort('403', 'Forbidden access'); |
||
| 37 | } |
||
| 38 | |||
| 39 | $this->model = $this->modelObject->model; |
||
| 40 | |||
| 41 | $this->checkPermissions(); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * |
||
| 46 | */ |
||
| 47 | protected function checkPermissions() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param $data |
||
| 63 | */ |
||
| 64 | protected function handleData($data) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param $data |
||
| 73 | * @return null |
||
| 74 | */ |
||
| 75 | protected function getFields($data) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @return array |
||
| 90 | */ |
||
| 91 | protected function getSort() |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @return array |
||
| 114 | */ |
||
| 115 | protected function getRules() |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param $items |
||
| 130 | * @return null |
||
| 131 | */ |
||
| 132 | public static function getCurrentModelId($items) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return array|mixed |
||
| 139 | */ |
||
| 140 | protected function filterInputData() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param $keys |
||
| 160 | * @param $values |
||
| 161 | * @return mixed |
||
| 162 | */ |
||
| 163 | protected function except($keys, $values) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param $data |
||
| 176 | * @return array |
||
| 177 | */ |
||
| 178 | protected function handleFiles($data) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param $type |
||
| 200 | * @return bool |
||
| 201 | */ |
||
| 202 | protected function isFileInput($type) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * This is used for simple upload (no plugins) |
||
| 209 | * |
||
| 210 | * @param $fieldName |
||
| 211 | * @param null $path |
||
| 212 | * @return string |
||
| 213 | */ |
||
| 214 | protected function uploadFile($fieldName, $path = null) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @param $modelName |
||
| 235 | * @param $id |
||
| 236 | * @param $field |
||
| 237 | * @return null |
||
| 238 | */ |
||
| 239 | protected function getRelatedFieldOutput($modelName, $id, $field) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @param $validator |
||
| 264 | * @param string $route |
||
| 265 | * @return $this |
||
| 266 | */ |
||
| 267 | protected function redirect($validator, $route, $id = null) |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @param $data |
||
| 286 | * @return \Illuminate\Validation\Validator |
||
| 287 | */ |
||
| 288 | protected function validator($data) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @param $modelName |
||
| 295 | * @param null $data |
||
| 296 | * @param $sort |
||
| 297 | * @return $this |
||
| 298 | */ |
||
| 299 | protected function all($modelName, $data = null, $sort) |
||
| 307 | } |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.