Complex classes like UploadJobStatus 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 UploadJobStatus, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 8 | class UploadJobStatus |
||
| 9 | { |
||
| 10 | |||
| 11 | use HydratableTrait; |
||
| 12 | |||
| 13 | protected $phase; |
||
| 14 | protected $start_time; |
||
| 15 | protected $uploaded_time; |
||
| 16 | protected $validated_time; |
||
| 17 | protected $completed_time; |
||
| 18 | protected $error_code; |
||
| 19 | protected $time_to_process; |
||
| 20 | protected $percent_complete; |
||
| 21 | protected $num_valid; |
||
| 22 | protected $num_valid_user; |
||
| 23 | protected $num_invalid_format; |
||
| 24 | protected $num_invalid_user; |
||
| 25 | protected $num_invalid_segment; |
||
| 26 | protected $num_unauth_segment; |
||
| 27 | protected $num_past_expiration; |
||
| 28 | protected $num_inactive_segment; |
||
| 29 | protected $num_other_error; |
||
| 30 | protected $error_log_lines; |
||
| 31 | protected $segment_log_lines; |
||
| 32 | protected $id; |
||
| 33 | protected $job_id; |
||
| 34 | protected $member_id; |
||
| 35 | protected $created_on; |
||
| 36 | protected $last_modified; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function getPhase() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param mixed $phase |
||
| 48 | */ |
||
| 49 | public function setPhase($phase) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return mixed |
||
| 56 | */ |
||
| 57 | public function getStartTime() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @param mixed $start_time |
||
| 64 | */ |
||
| 65 | public function setStartTime($start_time) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return mixed |
||
| 72 | */ |
||
| 73 | public function getUploadedTime() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param mixed $uploaded_time |
||
| 80 | */ |
||
| 81 | public function setUploadedTime($uploaded_time) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @return mixed |
||
| 88 | */ |
||
| 89 | public function getValidatedTime() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param mixed $validated_time |
||
| 96 | */ |
||
| 97 | public function setValidatedTime($validated_time) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @return mixed |
||
| 104 | */ |
||
| 105 | public function getCompletedTime() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @param mixed $completed_time |
||
| 112 | */ |
||
| 113 | public function setCompletedTime($completed_time) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @return mixed |
||
| 120 | */ |
||
| 121 | public function getErrorCode() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param mixed $error_code |
||
| 128 | */ |
||
| 129 | public function setErrorCode($error_code) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return mixed |
||
| 136 | */ |
||
| 137 | public function getTimeToProcess() |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param mixed $time_to_process |
||
| 144 | */ |
||
| 145 | public function setTimeToProcess($time_to_process) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @return mixed |
||
| 152 | */ |
||
| 153 | public function getPercentComplete() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param mixed $percent_complete |
||
| 160 | */ |
||
| 161 | public function setPercentComplete($percent_complete) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @return mixed |
||
| 168 | */ |
||
| 169 | public function getNumValid() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param mixed $num_valid |
||
| 176 | */ |
||
| 177 | public function setNumValid($num_valid) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @return mixed |
||
| 184 | */ |
||
| 185 | public function getNumValidUser() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param mixed $num_valid_user |
||
| 192 | */ |
||
| 193 | public function setNumValidUser($num_valid_user) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @return mixed |
||
| 200 | */ |
||
| 201 | public function getNumInvalidFormat() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param mixed $num_invalid_format |
||
| 208 | */ |
||
| 209 | public function setNumInvalidFormat($num_invalid_format) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @return mixed |
||
| 216 | */ |
||
| 217 | public function getNumInvalidUser() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @param mixed $num_invalid_user |
||
| 224 | */ |
||
| 225 | public function setNumInvalidUser($num_invalid_user) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @return mixed |
||
| 232 | */ |
||
| 233 | public function getNumInvalidSegment() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @param mixed $num_invalid_segment |
||
| 240 | */ |
||
| 241 | public function setNumInvalidSegment($num_invalid_segment) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @return mixed |
||
| 248 | */ |
||
| 249 | public function getNumUnauthSegment() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @param mixed $num_unauth_segment |
||
| 256 | */ |
||
| 257 | public function setNumUnauthSegment($num_unauth_segment) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @return mixed |
||
| 264 | */ |
||
| 265 | public function getNumPastExpiration() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @param mixed $num_past_expiration |
||
| 272 | */ |
||
| 273 | public function setNumPastExpiration($num_past_expiration) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return mixed |
||
| 280 | */ |
||
| 281 | public function getNumInactiveSegment() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param mixed $num_inactive_segment |
||
| 288 | */ |
||
| 289 | public function setNumInactiveSegment($num_inactive_segment) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @return mixed |
||
| 296 | */ |
||
| 297 | public function getNumOtherError() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @param mixed $num_other_error |
||
| 304 | */ |
||
| 305 | public function setNumOtherError($num_other_error) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @return mixed |
||
| 312 | */ |
||
| 313 | public function getErrorLogLines() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param mixed $error_log_lines |
||
| 320 | */ |
||
| 321 | public function setErrorLogLines($error_log_lines) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * @return mixed |
||
| 328 | */ |
||
| 329 | public function getSegmentLogLines() |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @param mixed $segment_log_lines |
||
| 336 | */ |
||
| 337 | public function setSegmentLogLines($segment_log_lines) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @return mixed |
||
| 344 | */ |
||
| 345 | public function getId() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @param mixed $id |
||
| 352 | */ |
||
| 353 | public function setId($id) |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @return mixed |
||
| 360 | */ |
||
| 361 | public function getJobId() |
||
| 365 | |||
| 366 | /** |
||
| 367 | * @param mixed $job_id |
||
| 368 | */ |
||
| 369 | public function setJobId($job_id) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @return mixed |
||
| 376 | */ |
||
| 377 | public function getMemberId() |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @param mixed $member_id |
||
| 384 | */ |
||
| 385 | public function setMemberId($member_id) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @return mixed |
||
| 392 | */ |
||
| 393 | public function getCreatedOn() |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @param mixed $created_on |
||
| 400 | */ |
||
| 401 | public function setCreatedOn($created_on) |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @return mixed |
||
| 408 | */ |
||
| 409 | public function getLastModified() |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @param mixed $last_modified |
||
| 416 | */ |
||
| 417 | public function setLastModified($last_modified) |
||
| 421 | } |
||
| 422 |