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 |
||
32 | class RecordWrapper implements \ArrayAccess, \Countable, \Iterator |
||
33 | { |
||
34 | use \ntentan\panie\ComponentContainerTrait; |
||
35 | |||
36 | protected $hasMany = []; |
||
37 | protected $belongsTo = []; |
||
38 | protected $manyHaveMany = []; |
||
39 | protected $behaviours = []; |
||
40 | protected $table; |
||
41 | private $modelData = []; |
||
42 | private $invalidFields; |
||
43 | private $dynamicOperations; |
||
44 | private $index = 0; |
||
45 | private $dataSet = false; |
||
46 | protected $adapter; |
||
47 | |||
48 | 36 | public function __construct(DriverAdapter $adapter) |
|
57 | |||
58 | /** |
||
59 | * |
||
60 | * @return ModelDescription |
||
61 | */ |
||
62 | 28 | public function getDescription() |
|
72 | |||
73 | 10 | public function count() |
|
81 | |||
82 | 12 | private function retrieveItem($key) |
|
91 | |||
92 | /** |
||
93 | * Create a new instance of this Model |
||
94 | * @return \ntentan\nibii\RecordWrapper |
||
95 | */ |
||
96 | 34 | public static function createNew() |
|
101 | |||
102 | /** |
||
103 | * @method |
||
104 | * @param type $name |
||
105 | * @param type $arguments |
||
106 | * @return type |
||
107 | */ |
||
108 | 34 | public function __call($name, $arguments) |
|
117 | |||
118 | 26 | public static function __callStatic($name, $arguments) |
|
122 | |||
123 | 8 | public function __set($name, $value) |
|
128 | |||
129 | 12 | public function __get($name) |
|
133 | |||
134 | 36 | public function getTable() |
|
138 | |||
139 | 4 | private function expandArrayValue($array, $relationships, $depth, $index = null) |
|
146 | |||
147 | 16 | public function toArray($depth = 0) |
|
162 | |||
163 | 10 | public function save() |
|
169 | |||
170 | public function isValid() |
||
174 | |||
175 | 18 | private function hasMultipleData() |
|
183 | |||
184 | 14 | public function getData() |
|
198 | |||
199 | 26 | public function setData($data) |
|
204 | |||
205 | public function mergeData($data) |
||
212 | |||
213 | 2 | public function offsetExists($offset) |
|
217 | |||
218 | 2 | public function offsetGet($offset) |
|
226 | |||
227 | 2 | public function offsetSet($offset, $value) |
|
232 | |||
233 | public function offsetUnset($offset) |
||
237 | |||
238 | 6 | private function wrap($offset) |
|
248 | |||
249 | 4 | public function getInvalidFields() |
|
253 | |||
254 | public function getHasMany() |
||
258 | |||
259 | public function getBelongsTo() |
||
263 | |||
264 | 4 | public function current() |
|
268 | |||
269 | public function key() |
||
273 | |||
274 | 4 | public function next() |
|
278 | |||
279 | 4 | public function rewind() |
|
283 | |||
284 | 4 | public function valid() |
|
288 | |||
289 | 12 | private function fetchRelatedFields($relationship, $index = null) |
|
303 | |||
304 | 28 | public function getRelationships() |
|
312 | |||
313 | public function usetField($field) |
||
317 | |||
318 | 8 | public function preSaveCallback() |
|
322 | |||
323 | 4 | public function postSaveCallback($id) |
|
327 | |||
328 | 2 | public function preUpdateCallback() |
|
332 | |||
333 | 2 | public function postUpdateCallback() |
|
337 | |||
338 | 10 | public function getBehaviours() |
|
342 | } |
||
343 |
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: