Complex classes like Model 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 Model, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | /** |
||
| 14 | * Indicates if the IDs are auto-incrementing. |
||
| 15 | * This is not possible in cassandra so we override this |
||
| 16 | * |
||
| 17 | * @var bool |
||
| 18 | */ |
||
| 19 | public $incrementing = false; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @inheritdoc |
||
| 23 | */ |
||
| 24 | public function newEloquentBuilder($query) |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @inheritdoc |
||
| 31 | */ |
||
| 32 | protected function newBaseQueryBuilder() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @inheritdoc |
||
| 41 | */ |
||
| 42 | public function freshTimestamp() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @inheritdoc |
||
| 49 | */ |
||
| 50 | public function fromDateTime($value) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @inheritdoc |
||
| 67 | */ |
||
| 68 | protected function asDateTime($value) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @inheritdoc |
||
| 80 | */ |
||
| 81 | protected function originalIsNumericallyEquivalent($key) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Get the table qualified key name. |
||
| 99 | * Cassandra does not support the table.column annotation so |
||
| 100 | * we override this |
||
| 101 | * |
||
| 102 | * @return string |
||
| 103 | */ |
||
| 104 | public function getQualifiedKeyName() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Set a given attribute on the model. |
||
| 111 | * |
||
| 112 | * @param string $key |
||
| 113 | * @param mixed $value |
||
| 114 | * @return $this |
||
| 115 | */ |
||
| 116 | public function setAttribute($key, $value) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @inheritdoc |
||
| 152 | */ |
||
| 153 | public function __call($method, $parameters) |
||
| 162 | } |
||
| 163 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.