Complex classes like AssignmentModel 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 AssignmentModel, and based on these observations, apply Extract Interface, too.
| 1 | <?php namespace Anomaly\Streams\Platform\Assignment; |
||
| 17 | class AssignmentModel extends EloquentModel implements AssignmentInterface, PresentableInterface |
||
| 18 | { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Do not use timestamps. |
||
| 22 | * |
||
| 23 | * @var bool |
||
| 24 | */ |
||
| 25 | public $timestamps = false; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Default attributes. |
||
| 29 | * |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | protected $attributes = [ |
||
| 33 | 'config' => 'a:0:{}', |
||
| 34 | ]; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The cache minutes. |
||
| 38 | * |
||
| 39 | * @var int |
||
| 40 | */ |
||
| 41 | protected $cacheMinutes = 99999; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The foreign key for translations. |
||
| 45 | * |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | protected $translationForeignKey = 'assignment_id'; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Translatable attributes. |
||
| 52 | * |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | protected $translatedAttributes = [ |
||
| 56 | 'label', |
||
| 57 | 'warning', |
||
| 58 | 'placeholder', |
||
| 59 | 'instructions', |
||
| 60 | ]; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * The translation model. |
||
| 64 | * |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | protected $translationModel = 'Anomaly\Streams\Platform\Assignment\AssignmentModelTranslation'; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * The database table name. |
||
| 71 | * |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | protected $table = 'streams_assignments'; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Because the assignment record holds translatable data |
||
| 78 | * we have a conflict. The assignment table has translations |
||
| 79 | * but not all assignment are translatable. This helps avoid |
||
| 80 | * the translatable conflict during specific procedures. |
||
| 81 | * |
||
| 82 | * @param array $attributes |
||
| 83 | * @return static |
||
| 84 | */ |
||
| 85 | public static function create(array $attributes = []) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Set the field attribute. |
||
| 96 | * |
||
| 97 | * @param FieldInterface $field |
||
| 98 | */ |
||
| 99 | public function setFieldAttribute(FieldInterface $field) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Set the stream attribute. |
||
| 106 | * |
||
| 107 | * @param StreamInterface $stream |
||
| 108 | */ |
||
| 109 | public function setStreamAttribute(StreamInterface $stream) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Get the field slug. |
||
| 116 | * |
||
| 117 | * @return string |
||
| 118 | */ |
||
| 119 | public function getFieldSlug() |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Get the assignment's field's type. |
||
| 132 | * |
||
| 133 | * @param bool $fresh |
||
| 134 | * @return FieldType|null |
||
| 135 | */ |
||
| 136 | public function getFieldType($fresh = false) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Get the field type value. This helps |
||
| 159 | * avoid spinning up a type instance |
||
| 160 | * if you don't really need it. |
||
| 161 | * |
||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | public function getFieldTypeValue() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Get the field name. |
||
| 173 | * |
||
| 174 | * @return string |
||
| 175 | */ |
||
| 176 | public function getFieldName() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Get the assignment's field's config. |
||
| 185 | * |
||
| 186 | * @return string |
||
| 187 | */ |
||
| 188 | public function getFieldConfig() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Get the assignment's field's rules. |
||
| 197 | * |
||
| 198 | * @return array |
||
| 199 | */ |
||
| 200 | public function getFieldRules() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Get the config. |
||
| 209 | * |
||
| 210 | * @return array |
||
| 211 | */ |
||
| 212 | public function getConfig() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Get the label. |
||
| 227 | * |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | public function getLabel() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Get the warning. |
||
| 237 | * |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | public function getWarning() |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Get the instructions. |
||
| 247 | * |
||
| 248 | * @return null |
||
| 249 | */ |
||
| 250 | public function getInstructions() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Get the placeholder. |
||
| 257 | * |
||
| 258 | * @return null |
||
| 259 | */ |
||
| 260 | public function getPlaceholder() |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Get the related stream. |
||
| 267 | * |
||
| 268 | * @return StreamInterface |
||
| 269 | */ |
||
| 270 | public function getStream() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Get the related stream's slug. |
||
| 277 | * |
||
| 278 | * @return string |
||
| 279 | */ |
||
| 280 | public function getStreamSlug() |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Get the related stream's prefix. |
||
| 291 | * |
||
| 292 | * @return string |
||
| 293 | */ |
||
| 294 | public function getStreamPrefix() |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Get the related field. |
||
| 305 | * |
||
| 306 | * @return FieldInterface |
||
| 307 | */ |
||
| 308 | public function getField() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Get the related field ID. |
||
| 319 | * |
||
| 320 | * @return null|int |
||
| 321 | */ |
||
| 322 | public function getFieldId() |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Get the unique flag. |
||
| 335 | * |
||
| 336 | * @return mixed |
||
| 337 | */ |
||
| 338 | public function isUnique() |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Get the required flag. |
||
| 345 | * |
||
| 346 | * @return bool |
||
| 347 | */ |
||
| 348 | public function isRequired() |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Get the translatable flag. |
||
| 355 | * |
||
| 356 | * @return bool |
||
| 357 | */ |
||
| 358 | public function isTranslatable() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Get the column name. |
||
| 371 | * |
||
| 372 | * @return mixed |
||
| 373 | */ |
||
| 374 | public function getColumnName() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Set config attribute. |
||
| 383 | * |
||
| 384 | * @param array $config |
||
| 385 | */ |
||
| 386 | public function setConfigAttribute($config) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Return the decoded config attribute. |
||
| 393 | * |
||
| 394 | * @param $config |
||
| 395 | * @return mixed |
||
| 396 | */ |
||
| 397 | public function getConfigAttribute($config) |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @param array $items |
||
| 408 | * @return AssignmentCollection |
||
| 409 | */ |
||
| 410 | public function newCollection(array $items = []) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Return a created presenter. |
||
| 417 | * |
||
| 418 | * @return AssignmentPresenter |
||
| 419 | */ |
||
| 420 | public function getPresenter() |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Compile the assignment's stream. |
||
| 427 | * |
||
| 428 | * @return AssignmentInterface |
||
| 429 | */ |
||
| 430 | public function compileStream() |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Return the stream relation. |
||
| 441 | * |
||
| 442 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
| 443 | */ |
||
| 444 | public function stream() |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Return the field relation. |
||
| 451 | * |
||
| 452 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
| 453 | */ |
||
| 454 | public function field() |
||
| 458 | } |
||
| 459 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.