Complex classes like Row 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 Row, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class Row extends BinderObject implements DumpToArrayInterface |
||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * \DOMNode represents a Row |
||
| 15 | * @var \DOMElement |
||
| 16 | */ |
||
| 17 | private $node = null; |
||
| 18 | private $row = null; |
||
| 19 | private $originalRow = null; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Row constructor |
||
| 23 | * @param array() |
||
| 24 | */ |
||
| 25 | 69 | public function __construct($instance = null) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * Add a string field to row |
||
| 41 | * @param string $name |
||
| 42 | * @param string $value |
||
| 43 | */ |
||
| 44 | 52 | public function addField($name, $value) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @param string $name - Field name |
||
| 58 | * @return string |
||
| 59 | * @desc et the string value from a field name |
||
| 60 | */ |
||
| 61 | 36 | public function get($name) |
|
| 74 | |||
| 75 | /** |
||
| 76 | * Get array from a single field |
||
| 77 | * |
||
| 78 | * @param string $fieldName |
||
| 79 | * @return array |
||
| 80 | */ |
||
| 81 | 4 | public function getAsArray($fieldName) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Return all Field Names from current Row |
||
| 98 | * @return array |
||
| 99 | */ |
||
| 100 | 1 | public function getFieldNames() |
|
| 104 | |||
| 105 | /** |
||
| 106 | * Set a string value to existing field name |
||
| 107 | * @param string $name |
||
| 108 | * @param string $value |
||
| 109 | */ |
||
| 110 | 9 | public function set($name, $value) |
|
| 119 | |||
| 120 | /** |
||
| 121 | * Remove specified field name from row. |
||
| 122 | * |
||
| 123 | * @param string $fieldName |
||
| 124 | */ |
||
| 125 | 2 | public function removeField($fieldName) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Remove specified field name with specified value name from row. |
||
| 135 | * |
||
| 136 | * @param string $fieldName |
||
| 137 | * @param $value |
||
| 138 | */ |
||
| 139 | 1 | public function removeValue($fieldName, $value) |
|
| 158 | |||
| 159 | /** |
||
| 160 | * Update a specific field and specific value with new value |
||
| 161 | * |
||
| 162 | * @param String $fieldName |
||
| 163 | * @param String $oldvalue |
||
| 164 | * @param String $newvalue |
||
| 165 | */ |
||
| 166 | 1 | public function replaceValue($fieldName, $oldvalue, $newvalue) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * Get the \DOMElement row objet |
||
| 186 | * |
||
| 187 | * @return \DOMElement |
||
| 188 | * @throws \ByJG\Util\Exception\XmlUtilException |
||
| 189 | */ |
||
| 190 | 3 | public function getAsDom() |
|
| 209 | |||
| 210 | 30 | public function toArray() |
|
| 214 | |||
| 215 | /** |
||
| 216 | * |
||
| 217 | * @return array |
||
| 218 | */ |
||
| 219 | public function getAsJSON() |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @return array |
||
| 232 | */ |
||
| 233 | 2 | public function getAsRaw() |
|
| 237 | |||
| 238 | /** |
||
| 239 | * |
||
| 240 | * @return bool |
||
| 241 | */ |
||
| 242 | 1 | public function hasChanges() |
|
| 246 | |||
| 247 | /** |
||
| 248 | * |
||
| 249 | */ |
||
| 250 | 69 | public function acceptChanges() |
|
| 254 | |||
| 255 | /** |
||
| 256 | * |
||
| 257 | */ |
||
| 258 | 1 | public function rejectChanges() |
|
| 262 | |||
| 263 | 52 | protected function informChanges() |
|
| 267 | |||
| 268 | /** |
||
| 269 | * Override Specific implementation of setPropValue to Row |
||
| 270 | * |
||
| 271 | * @param Row $obj |
||
| 272 | * @param string $propName |
||
| 273 | * @param string $value |
||
| 274 | */ |
||
| 275 | 4 | protected function setPropValue($obj, $propName, $value) |
|
| 279 | } |
||
| 280 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..