Complex classes like RecordWrapper 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 RecordWrapper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | class RecordWrapper implements \ArrayAccess, \Countable, \Iterator { |
||
38 | |||
39 | use \ntentan\panie\ComponentContainerTrait; |
||
40 | |||
41 | protected $hasMany = []; |
||
42 | protected $belongsTo = []; |
||
43 | protected $manyHaveMany = []; |
||
44 | protected $behaviours = []; |
||
45 | protected $table; |
||
46 | protected $schema; |
||
47 | private $quotedTable; |
||
48 | private $unquotedTable; |
||
49 | private $modelData = []; |
||
50 | private $invalidFields; |
||
51 | private $dynamicOperations; |
||
52 | private $index = 0; |
||
53 | private $dataSet = false; |
||
54 | |||
55 | /** |
||
56 | * |
||
57 | * @var DriverAdapter |
||
58 | */ |
||
59 | private $adapter; |
||
60 | private $container; |
||
61 | private $context; |
||
62 | private $keys = []; |
||
63 | private $initialized = false; |
||
64 | |||
65 | 37 | private function initialize() { |
|
89 | |||
90 | public function __debugInfo() { |
||
94 | |||
95 | /** |
||
96 | * |
||
97 | * @return ModelDescription |
||
98 | */ |
||
99 | 28 | public function getDescription() { |
|
107 | |||
108 | /** |
||
109 | * Return the number of items stored in the model or the query. |
||
110 | * @return integer |
||
111 | */ |
||
112 | 14 | public function count() { |
|
119 | |||
120 | /** |
||
121 | * Retrieve an item stored in the record. |
||
122 | * This method returns items that are directly stored in the model or lazy |
||
123 | * loads related items. The key could be a field in the model's table or |
||
124 | * the name of a related model. |
||
125 | * @param string $key A key identifying the item to be retrieved. |
||
126 | * @return mixed |
||
127 | */ |
||
128 | 12 | private function retrieveItem($key) { |
|
136 | |||
137 | /** |
||
138 | * Create a new instance of this Model |
||
139 | * @return \ntentan\nibii\RecordWrapper |
||
140 | */ |
||
141 | 35 | public static function createNew() { |
|
146 | |||
147 | /** |
||
148 | * @method |
||
149 | * @param type $name |
||
150 | * @param type $arguments |
||
151 | * @return type |
||
152 | */ |
||
153 | 35 | public function __call($name, $arguments) { |
|
165 | |||
166 | 27 | public static function __callStatic($name, $arguments) { |
|
169 | |||
170 | 8 | public function __set($name, $value) { |
|
174 | |||
175 | 12 | public function __get($name) { |
|
178 | |||
179 | 4 | private function expandArrayValue($array, $relationships, $depth, $index = null) { |
|
185 | |||
186 | 16 | public function toArray($depth = 0) { |
|
200 | |||
201 | 10 | public function save() { |
|
206 | |||
207 | 18 | private function hasMultipleItems() { |
|
214 | |||
215 | 18 | public function getData() { |
|
228 | |||
229 | 27 | public function setData($data) { |
|
233 | |||
234 | public function mergeData($data) { |
||
240 | |||
241 | 2 | public function offsetExists($offset) { |
|
244 | |||
245 | 2 | public function offsetGet($offset) { |
|
252 | |||
253 | 2 | public function offsetSet($offset, $value) { |
|
257 | |||
258 | public function offsetUnset($offset) { |
||
261 | |||
262 | 6 | private function wrap($offset) { |
|
271 | |||
272 | public function getInvalidFields() { |
||
275 | |||
276 | public function getHasMany() { |
||
279 | |||
280 | public function getBelongsTo() { |
||
283 | |||
284 | 4 | public function current() { |
|
287 | |||
288 | public function key() { |
||
291 | |||
292 | 4 | public function next() { |
|
295 | |||
296 | 4 | public function rewind() { |
|
300 | |||
301 | 4 | public function valid() { |
|
304 | |||
305 | 10 | public function onValidate($errors) { |
|
308 | |||
309 | 12 | private function fetchRelatedFields($relationship, $index = null) { |
|
322 | |||
323 | 28 | public function getRelationships() { |
|
330 | |||
331 | public function usetField($field) { |
||
334 | |||
335 | 8 | public function preSaveCallback() { |
|
338 | |||
339 | 4 | public function postSaveCallback($id) { |
|
342 | |||
343 | 2 | public function preUpdateCallback() { |
|
346 | |||
347 | 2 | public function postUpdateCallback() { |
|
350 | |||
351 | 37 | public function getDBStoreInformation() { |
|
360 | |||
361 | /** |
||
362 | * |
||
363 | * @return DataAdapter |
||
364 | */ |
||
365 | public function getAdapter() { |
||
369 | |||
370 | } |
||
371 |
This check looks for function calls that miss required arguments.