Complex classes like TResultProperty 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 TResultProperty, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 41 | class TResultProperty extends \Prado\TComponent |
||
| 42 | { |
||
| 43 | private $_nullValue; |
||
| 44 | private $_propertyName; |
||
| 45 | private $_columnName; |
||
| 46 | private $_columnIndex = -1; |
||
| 47 | private $_nestedResultMapName; |
||
| 48 | private $_nestedResultMap; |
||
| 49 | private $_valueType; |
||
| 50 | private $_typeHandler; |
||
| 51 | private $_isLazyLoad = false; |
||
| 52 | private $_select; |
||
| 53 | |||
| 54 | private $_hostResultMapID = 'inplicit internal mapping'; |
||
| 55 | |||
| 56 | const LIST_TYPE = 0; |
||
| 57 | const ARRAY_TYPE = 1; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Gets the containing result map ID. |
||
| 61 | * @param TResultMap $resultMap containing result map. |
||
| 62 | */ |
||
| 63 | 23 | public function __construct($resultMap = null) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * @return mixed null value replacement. |
||
| 72 | */ |
||
| 73 | 33 | public function getNullValue() |
|
| 77 | |||
| 78 | /** |
||
| 79 | * @param mixed $value null value replacement. |
||
| 80 | */ |
||
| 81 | public function setNullValue($value) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @return string name of a property of the result object that will be set to. |
||
| 88 | */ |
||
| 89 | 69 | public function getProperty() |
|
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $value name of a property of the result object that will be set to. |
||
| 96 | */ |
||
| 97 | public function setProperty($value) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @return string name of the column in the result set from which the value |
||
| 104 | * will be used to populate the property. |
||
| 105 | */ |
||
| 106 | 83 | public function getColumn() |
|
| 110 | |||
| 111 | /** |
||
| 112 | * @param string $value name of the column in the result set from which the value |
||
| 113 | * will be used to populate the property. |
||
| 114 | */ |
||
| 115 | 23 | public function setColumn($value) |
|
| 119 | |||
| 120 | /** |
||
| 121 | * @return int index of the column in the ResultSet from which the value will |
||
| 122 | * be used to populate the object property |
||
| 123 | */ |
||
| 124 | 83 | public function getColumnIndex() |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @param int $value index of the column in the ResultSet from which the value will |
||
| 131 | * be used to populate the object property |
||
| 132 | */ |
||
| 133 | 23 | public function setColumnIndex($value) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * @return string ID of another <resultMap> used to fill the property. |
||
| 140 | */ |
||
| 141 | 1 | public function getResultMapping() |
|
| 145 | |||
| 146 | /** |
||
| 147 | * @param string $value ID of another <resultMap> used to fill the property. |
||
| 148 | */ |
||
| 149 | public function setResultMapping($value) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return TResultMap nested result map. |
||
| 156 | */ |
||
| 157 | 61 | public function getNestedResultMap() |
|
| 161 | |||
| 162 | /** |
||
| 163 | * @param TResult $value nested result map. |
||
| 164 | */ |
||
| 165 | public function setNestedResultMap($value) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @return string property type of the object property to be set. |
||
| 172 | */ |
||
| 173 | 83 | public function getType() |
|
| 177 | |||
| 178 | /** |
||
| 179 | * @param string $value property type of the object property to be set. |
||
| 180 | */ |
||
| 181 | 30 | public function setType($value) |
|
| 185 | |||
| 186 | /** |
||
| 187 | * @return string custom type handler class name (may use namespace). |
||
| 188 | */ |
||
| 189 | 83 | public function getTypeHandler() |
|
| 193 | |||
| 194 | /** |
||
| 195 | * @param string $value custom type handler class name (may use namespace). |
||
| 196 | */ |
||
| 197 | public function setTypeHandler($value) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @return string name of another mapped statement |
||
| 204 | */ |
||
| 205 | 61 | public function getSelect() |
|
| 209 | |||
| 210 | /** |
||
| 211 | * The select property is used to describe a relationship between objects |
||
| 212 | * and to automatically load complex (i.e. user defined) property types. |
||
| 213 | * @param string $value name of another mapped statement. |
||
| 214 | */ |
||
| 215 | public function setSelect($value) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return bool indicate whether or not the select statement's results should be lazy loaded |
||
| 222 | */ |
||
| 223 | 10 | public function getLazyLoad() |
|
| 227 | |||
| 228 | /** |
||
| 229 | * @param bool $value indicate whether or not the select statement's results should be lazy loaded |
||
| 230 | */ |
||
| 231 | public function setLazyLoad($value) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Gets the value for the current property, converts to applicable type if necessary. |
||
| 238 | * @param TSqlMapTypeHandlerRegistry $registry type handler registry |
||
| 239 | * @param array $row result row |
||
| 240 | * @return mixed property value. |
||
| 241 | */ |
||
| 242 | 83 | public function getPropertyValue($registry, $row) |
|
| 257 | |||
| 258 | /** |
||
| 259 | * @param TSqlMapTypeHandlerRegistry $registry type handler registry |
||
| 260 | * @param mixed $value raw property value |
||
| 261 | * @return mixed property value casted to specific type. |
||
| 262 | */ |
||
| 263 | 83 | protected function getTypedValue($registry, $value) |
|
| 271 | |||
| 272 | /** |
||
| 273 | * Create type handler from {@link Type setType()} or {@link TypeHandler setTypeHandler}. |
||
| 274 | * @param TSqlMapTypeHandlerRegistry $registry type handler registry |
||
| 275 | * @return TSqlMapTypeHandler type handler. |
||
| 276 | */ |
||
| 277 | 83 | protected function createTypeHandler($registry) |
|
| 286 | |||
| 287 | /** |
||
| 288 | * Determines if the type is an instance of \ArrayAccess, TList or an array. |
||
| 289 | * @return int TResultProperty::LIST_TYPE or TResultProperty::ARRAY_TYPE |
||
| 290 | */ |
||
| 291 | 4 | protected function getPropertyValueType() |
|
| 292 | { |
||
| 293 | 4 | if (class_exists($type = $this->getType(), false)) { //NO force autoloading |
|
| 294 | 3 | if ($type === 'TList') { |
|
| 295 | 3 | return self::LIST_TYPE; |
|
| 296 | } |
||
| 297 | $class = new ReflectionClass($type); |
||
| 298 | if ($class->isSubclassOf('TList')) { |
||
| 299 | return self::LIST_TYPE; |
||
| 300 | } |
||
| 301 | if ($class->implementsInterface('ArrayAccess')) { |
||
| 302 | return self::ARRAY_TYPE; |
||
| 303 | } |
||
| 304 | } |
||
| 305 | 1 | if (strtolower($type) == 'array') { |
|
| 306 | return self::ARRAY_TYPE; |
||
| 307 | } |
||
| 308 | 1 | } |
|
| 309 | |||
| 310 | /** |
||
| 311 | * Returns true if the result property {@link Type getType()} is of TList type |
||
| 312 | * or that the actual result object is an instance of TList. |
||
| 313 | * @param object $target result object |
||
| 314 | * @return bool true if the result object is an instance of TList |
||
| 315 | */ |
||
| 316 | 14 | public function instanceOfListType($target) |
|
| 323 | |||
| 324 | /** |
||
| 325 | * Returns true if the result property {@link Type getType()} is of \ArrayAccess |
||
| 326 | * or that the actual result object is an array or implements \ArrayAccess |
||
| 327 | * @param object $target result object |
||
| 328 | * @return bool true if the result object is an instance of \ArrayAccess or is an array. |
||
| 329 | */ |
||
| 330 | 7 | public function instanceOfArrayType($target) |
|
| 341 | |||
| 342 | public function __sleep() |
||
| 378 | } |
||
| 379 |