Complex classes like AbstractField 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 AbstractField, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | abstract class AbstractField implements FieldPropsInterface |
||
| 11 | { |
||
| 12 | const DEFAULT_TAB_IDENT = '[extra]'; |
||
| 13 | |||
| 14 | protected $model = ''; |
||
| 15 | protected $title = ''; |
||
| 16 | protected $name = ''; |
||
| 17 | protected $readonly = false; |
||
| 18 | protected $default = null; |
||
| 19 | protected $hidden = [ |
||
| 20 | 'list' => false, |
||
| 21 | 'edit' => false, |
||
| 22 | 'create' => false, |
||
| 23 | ]; |
||
| 24 | protected $width; |
||
| 25 | protected $filter = null; |
||
| 26 | protected $tab = self::DEFAULT_TAB_IDENT; |
||
| 27 | protected $col = 12; |
||
| 28 | |||
| 29 | 481 | public static function make($name = '', $title = '') |
|
| 41 | |||
| 42 | 14 | public function setModel($model) |
|
| 46 | |||
| 47 | 14 | public function getModel() |
|
| 51 | |||
| 52 | 8 | public function value(Request $request) |
|
| 61 | |||
| 62 | 12 | public function shouldSkip(Request $request) |
|
| 63 | { |
||
| 64 | 12 | return false; |
|
| 65 | } |
||
| 66 | |||
| 67 | 14 | public function col(int $col) |
|
| 73 | |||
| 74 | 28 | public function getCol() |
|
| 78 | |||
| 79 | 28 | public function filter(AbstractFilter $filter = null) |
|
| 91 | |||
| 92 | 14 | public function tab(string $tab) |
|
| 98 | |||
| 99 | 28 | public function getTab() |
|
| 103 | |||
| 104 | 481 | public function title(string $title = null) |
|
| 114 | |||
| 115 | 481 | public function name(string $name = null) |
|
| 125 | |||
| 126 | 14 | public function readonly(bool $isReadonly = true) |
|
| 132 | |||
| 133 | 40 | public function isReadonly() |
|
| 137 | |||
| 138 | 11 | public function default($value) |
|
| 144 | |||
| 145 | 34 | public function getDefault() |
|
| 149 | |||
| 150 | public function old($name = null) |
||
| 158 | |||
| 159 | public function hasOld($name = null) |
||
| 163 | |||
| 164 | public function oldOrDefault($locale = null) |
||
| 177 | |||
| 178 | public function oldOrAttribute($model, $default = null, $locale = null) |
||
| 194 | |||
| 195 | public function getAttribute($model, $locale = null) |
||
| 203 | |||
| 204 | 14 | public function width(int $width) |
|
| 210 | |||
| 211 | 28 | public function getWidth() |
|
| 215 | |||
| 216 | public function hide(bool $edit = false, bool $create = false, bool $list = false) |
||
| 226 | |||
| 227 | 13 | public function hideList(bool $hide = false) |
|
| 233 | |||
| 234 | 13 | public function hideEdit(bool $hide = false) |
|
| 240 | |||
| 241 | 13 | public function hideCreate(bool $hide = false) |
|
| 247 | |||
| 248 | 28 | public function hidden(string $type) |
|
| 256 | |||
| 257 | public function afterStore($model, Request $request) |
||
| 261 | |||
| 262 | public function afterUpdate($model, Request $request) |
||
| 266 | |||
| 267 | 10 | public function isInline() |
|
| 271 | |||
| 272 | public function isRelationField() |
||
| 276 | |||
| 277 | public function isMultiple() |
||
| 281 | |||
| 282 | public function isEncode() |
||
| 286 | |||
| 287 | public function isMarkupRow() |
||
| 291 | |||
| 292 | public function isOrderable() |
||
| 296 | |||
| 297 | public function isAjax() |
||
| 301 | |||
| 302 | 3 | public function isNullable() |
|
| 306 | |||
| 307 | public function hasTooltip() |
||
| 311 | |||
| 312 | public function hasClipboardButton() |
||
| 316 | |||
| 317 | public function isTranslatable() |
||
| 321 | |||
| 322 | public function isMaskable() |
||
| 326 | |||
| 327 | public function getPlaceholder() |
||
| 331 | |||
| 332 | abstract public function getListValue($model); |
||
| 333 | |||
| 334 | abstract public function getEditFormValue($model); |
||
| 335 | |||
| 336 | abstract public function getCreateFormValue(); |
||
| 337 | |||
| 338 | // TODO: interface type-hinting |
||
| 339 | public function prepare(CRUD $crud) |
||
| 360 | } |
||
| 361 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.