Complex classes like SingleRow 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 SingleRow, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class SingleRow extends BinderObject implements DumpToArrayInterface |
||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * \DOMNode represents a SingleRow |
||
| 16 | * @var DOMNode |
||
| 17 | */ |
||
| 18 | private $_node = null; |
||
| 19 | private $_row = null; |
||
| 20 | private $_originalRow = null; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * SingleRow constructor |
||
| 24 | * @param array() |
||
| 25 | */ |
||
| 26 | public function __construct($instance = null) |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Add a string field to row |
||
| 42 | * @param string $name |
||
| 43 | * @param string $value |
||
| 44 | */ |
||
| 45 | public function addField($name, $value) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param string $name - Field name |
||
| 59 | * @return string |
||
| 60 | * @desc et the string value from a field name |
||
| 61 | */ |
||
| 62 | public function getField($name) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Get array from a single field |
||
| 78 | * |
||
| 79 | * @param string $name |
||
| 80 | * @return array |
||
| 81 | */ |
||
| 82 | public function getFieldArray($name) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Return all Field Names from current SingleRow |
||
| 100 | * @return array |
||
| 101 | */ |
||
| 102 | public function getFieldNames() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Set a string value to existing field name |
||
| 109 | * @param string $name |
||
| 110 | * @param string $value |
||
| 111 | */ |
||
| 112 | public function setField($name, $value) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Remove specified field name from row. |
||
| 124 | * @param string $name |
||
| 125 | */ |
||
| 126 | public function removeFieldName($name) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Remove specified field name with specified value name from row. |
||
| 136 | * @param string $name |
||
| 137 | * @param $value |
||
| 138 | */ |
||
| 139 | public function removeFieldNameValue($name, $value) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Update a specific field and specific value with new value |
||
| 161 | * |
||
| 162 | * @param String $name |
||
| 163 | * @param String $oldvalue |
||
| 164 | * @param String $newvalue |
||
| 165 | */ |
||
| 166 | public function setFieldValue($name, $oldvalue, $newvalue) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Get the \DOMNode row objet |
||
| 186 | * @return DOMNode |
||
| 187 | */ |
||
| 188 | public function getDomObject() |
||
| 207 | |||
| 208 | public function toArray() |
||
| 212 | |||
| 213 | /** |
||
| 214 | * |
||
| 215 | * @return array |
||
| 216 | */ |
||
| 217 | public function getAsJSON() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @return array |
||
| 228 | */ |
||
| 229 | public function getOriginalRawFormat() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * |
||
| 236 | * @return bool |
||
| 237 | */ |
||
| 238 | public function hasChanges() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * |
||
| 245 | * @return bool |
||
| 246 | */ |
||
| 247 | public function acceptChanges() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * |
||
| 254 | * @return bool |
||
| 255 | */ |
||
| 256 | public function rejectChanges() |
||
| 260 | |||
| 261 | protected function informChanges() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Override Specific implementation of setPropValue to SingleRow |
||
| 268 | * |
||
| 269 | * @param SingleRow $obj |
||
| 270 | * @param string $propName |
||
| 271 | * @param string $value |
||
| 272 | */ |
||
| 273 | protected function setPropValue($obj, $propName, $value) |
||
| 277 | |||
| 278 | |||
| 279 | } |
||
| 280 |