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 |
||
31 | class RecordWrapper implements \ArrayAccess, \Countable, \Iterator |
||
32 | { |
||
33 | use \ntentan\utils\DependencyInjector; |
||
34 | |||
35 | protected $hasMany = []; |
||
36 | protected $belongsTo = []; |
||
37 | protected $manyHaveMany = []; |
||
38 | protected $behaviours = []; |
||
39 | |||
40 | protected $table; |
||
41 | private $modelData = []; |
||
42 | private $invalidFields; |
||
43 | private $dynamicOperations; |
||
44 | private $index = 0; |
||
45 | private $dataSet = false; |
||
46 | private $adapter; |
||
47 | |||
48 | 36 | public function __construct() |
|
61 | |||
62 | /** |
||
63 | * |
||
64 | * @return \ntentan\nibii\DriverAdapter |
||
65 | */ |
||
66 | 34 | protected function getDataAdapter() |
|
74 | |||
75 | /** |
||
76 | * |
||
77 | * @return ModelDescription |
||
78 | */ |
||
79 | 28 | public function getDescription() |
|
89 | |||
90 | 10 | public function count() |
|
98 | |||
99 | 12 | private function retrieveItem($key) |
|
108 | |||
109 | /** |
||
110 | * Create a new instance of this Model |
||
111 | * @return \ntentan\nibii\RecordWrapper |
||
112 | */ |
||
113 | 34 | public static function createNew() |
|
118 | |||
119 | /** |
||
120 | * @method |
||
121 | * @param type $name |
||
122 | * @param type $arguments |
||
123 | * @return type |
||
124 | */ |
||
125 | 34 | public function __call($name, $arguments) |
|
133 | |||
134 | 26 | public static function __callStatic($name, $arguments) |
|
138 | |||
139 | 8 | public function __set($name, $value) |
|
144 | |||
145 | 12 | public function __get($name) |
|
149 | |||
150 | 32 | public function getTable() |
|
151 | { |
||
152 | 32 | return $this->table; |
|
153 | } |
||
154 | |||
155 | 4 | private function expandArrayValue($array, $relationships, $depth, $index = null) |
|
162 | |||
163 | 16 | public function toArray($depth = 0) |
|
178 | |||
179 | 10 | public function save() |
|
185 | |||
186 | 18 | private function hasMultipleData() |
|
194 | |||
195 | 14 | public function getData() |
|
209 | |||
210 | 26 | public function setData($data) |
|
215 | |||
216 | public function mergeData($data) |
||
223 | |||
224 | 2 | public function offsetExists($offset) |
|
228 | |||
229 | 2 | public function offsetGet($offset) |
|
237 | |||
238 | 2 | public function offsetSet($offset, $value) |
|
243 | |||
244 | public function offsetUnset($offset) |
||
248 | |||
249 | 6 | private function wrap($offset) |
|
259 | |||
260 | 4 | public function getInvalidFields() |
|
264 | |||
265 | public function getHasMany() |
||
269 | |||
270 | public function getBelongsTo() |
||
274 | |||
275 | 4 | public function current() |
|
279 | |||
280 | public function key() |
||
284 | |||
285 | 4 | public function next() |
|
289 | |||
290 | 4 | public function rewind() |
|
294 | |||
295 | 4 | public function valid() |
|
299 | |||
300 | 12 | private function fetchRelatedFields($relationship, $index = null) |
|
314 | |||
315 | 8 | public function getRelationships() |
|
323 | |||
324 | public function usetField($field) |
||
328 | |||
329 | 8 | public function preSaveCallback() |
|
333 | |||
334 | 4 | public function postSaveCallback($id) |
|
338 | |||
339 | 2 | public function preUpdateCallback() |
|
343 | |||
344 | 2 | public function postUpdateCallback() |
|
348 | |||
349 | 10 | public function getBehaviours() |
|
353 | } |
||
354 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: