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 |
||
| 33 | class RecordWrapper implements \ArrayAccess, \Countable, \Iterator |
||
| 34 | { |
||
| 35 | use \ntentan\panie\ComponentContainerTrait; |
||
| 36 | |||
| 37 | protected $hasMany = []; |
||
| 38 | protected $belongsTo = []; |
||
| 39 | protected $manyHaveMany = []; |
||
| 40 | protected $behaviours = []; |
||
| 41 | protected $table; |
||
| 42 | private $modelData = []; |
||
| 43 | private $invalidFields; |
||
| 44 | private $dynamicOperations; |
||
| 45 | private $index = 0; |
||
| 46 | private $dataSet = false; |
||
| 47 | protected $adapter; |
||
| 48 | |||
| 49 | 36 | public function __construct(DriverAdapter $adapter) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * |
||
| 61 | * @return ModelDescription |
||
| 62 | */ |
||
| 63 | 28 | public function getDescription() |
|
| 73 | |||
| 74 | 10 | public function count() |
|
| 82 | |||
| 83 | 12 | private function retrieveItem($key) |
|
| 92 | |||
| 93 | /** |
||
| 94 | * Create a new instance of this Model |
||
| 95 | * @return \ntentan\nibii\RecordWrapper |
||
| 96 | */ |
||
| 97 | 34 | public static function createNew() |
|
| 102 | |||
| 103 | /** |
||
| 104 | * @method |
||
| 105 | * @param type $name |
||
| 106 | * @param type $arguments |
||
| 107 | * @return type |
||
| 108 | */ |
||
| 109 | 34 | public function __call($name, $arguments) |
|
| 118 | |||
| 119 | 26 | public static function __callStatic($name, $arguments) |
|
| 123 | |||
| 124 | 8 | public function __set($name, $value) |
|
| 129 | |||
| 130 | 12 | public function __get($name) |
|
| 134 | |||
| 135 | 36 | public function getTable() |
|
| 139 | |||
| 140 | 4 | private function expandArrayValue($array, $relationships, $depth, $index = null) |
|
| 147 | |||
| 148 | 12 | public function toArray($depth = 0) |
|
| 163 | |||
| 164 | 10 | public function save() |
|
| 170 | |||
| 171 | 18 | private function hasMultipleData() |
|
| 179 | |||
| 180 | 14 | public function getData() |
|
| 194 | |||
| 195 | 26 | public function setData($data) |
|
| 200 | |||
| 201 | public function mergeData($data) |
||
| 208 | |||
| 209 | 2 | public function offsetExists($offset) |
|
| 213 | |||
| 214 | 2 | public function offsetGet($offset) |
|
| 222 | |||
| 223 | 2 | public function offsetSet($offset, $value) |
|
| 228 | |||
| 229 | public function offsetUnset($offset) |
||
| 233 | |||
| 234 | 6 | private function wrap($offset) |
|
| 244 | |||
| 245 | 4 | public function getInvalidFields() |
|
| 249 | |||
| 250 | public function getHasMany() |
||
| 254 | |||
| 255 | public function getBelongsTo() |
||
| 259 | |||
| 260 | 4 | public function current() |
|
| 264 | |||
| 265 | public function key() |
||
| 269 | |||
| 270 | 2 | public function next() |
|
| 274 | |||
| 275 | 4 | public function rewind() |
|
| 279 | |||
| 280 | 4 | public function valid() |
|
| 284 | |||
| 285 | 6 | public function onValidate() |
|
| 289 | |||
| 290 | 8 | private function fetchRelatedFields($relationship, $index = null) |
|
| 304 | |||
| 305 | 28 | public function getRelationships() |
|
| 313 | |||
| 314 | public function usetField($field) |
||
| 318 | |||
| 319 | 8 | public function preSaveCallback() |
|
| 323 | |||
| 324 | 4 | public function postSaveCallback($id) |
|
| 328 | |||
| 329 | 2 | public function preUpdateCallback() |
|
| 333 | |||
| 334 | 2 | public function postUpdateCallback() |
|
| 338 | |||
| 339 | 10 | public function getBehaviours() |
|
| 343 | } |
||
| 344 |
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: