| Total Complexity | 62 |
| Total Lines | 337 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like JobPoster 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.
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 JobPoster, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class JobPoster implements JsonSerializable { |
||
|
|
|||
| 15 | |||
| 16 | private $id; |
||
| 17 | private $locale_id; |
||
| 18 | private $manager_user_id; |
||
| 19 | private $title; |
||
| 20 | private $description; |
||
| 21 | private $applicants_to_date; |
||
| 22 | private $term_qty; |
||
| 23 | private $term_units; |
||
| 24 | private $job_min_level; |
||
| 25 | private $job_max_level; |
||
| 26 | private $start_date; |
||
| 27 | private $open_date; |
||
| 28 | private $close_date; |
||
| 29 | private $department; |
||
| 30 | private $branch; |
||
| 31 | private $division; |
||
| 32 | private $location_province; |
||
| 33 | private $location_city; |
||
| 34 | private $remuneration_range_low; |
||
| 35 | private $remuneration_range_high; |
||
| 36 | private $impact; |
||
| 37 | private $key_tasks; |
||
| 38 | private $core_competencies; |
||
| 39 | private $developing_competencies; |
||
| 40 | private $questions; |
||
| 41 | private $noc; |
||
| 42 | private $classification; |
||
| 43 | private $security_clearance; |
||
| 44 | private $language_requirement; |
||
| 45 | |||
| 46 | public function __construct($id = null, $locale_id = null, $manager_user_id = null, $title = null, $description = null, $applicants_to_date = null, $term_qty = null, $term_units = null, |
||
| 47 | $job_min_level = null, $job_max_level = null, $start_date = null, $open_date = null, $close_date = null, $department = null, $branch = null, $division = null, $location_province = null, |
||
| 48 | $location_city = null, $remuneration_range_low = null, $remuneration_range_high = null, $impact = null, $key_tasks = null, $core_competencies = null, $developing_competencies = null, |
||
| 49 | $questions = [], $noc = null, $classification = null, $security_clearance = null, $language_requirement = null) { |
||
| 50 | $this->id = $id; |
||
| 51 | $this->locale_id = $locale_id; |
||
| 52 | $this->manager_user_id = $manager_user_id; |
||
| 53 | $this->title = $title; |
||
| 54 | $this->description = $description; |
||
| 55 | $this->applicants_to_date = $applicants_to_date; |
||
| 56 | $this->term_qty = $term_qty; |
||
| 57 | $this->term_units = $term_units; |
||
| 58 | $this->job_min_level = $job_min_level; |
||
| 59 | $this->job_max_level = $job_max_level; |
||
| 60 | $this->start_date = $start_date; |
||
| 61 | $this->open_date = $open_date; |
||
| 62 | $this->close_date = $close_date; |
||
| 63 | $this->department = $department; |
||
| 64 | $this->branch = $branch; |
||
| 65 | $this->division = $division; |
||
| 66 | $this->location_province = $location_province; |
||
| 67 | $this->location_city = $location_city; |
||
| 68 | $this->remuneration_range_low = $remuneration_range_low; |
||
| 69 | $this->remuneration_range_high = $remuneration_range_high; |
||
| 70 | $this->impact = $impact; |
||
| 71 | $this->key_tasks = $key_tasks; |
||
| 72 | $this->core_competencies = $core_competencies; |
||
| 73 | $this->developing_competencies = $developing_competencies; |
||
| 74 | $this->questions = $questions; |
||
| 75 | $this->noc = $noc; |
||
| 76 | $this->classification = $classification; |
||
| 77 | $this->security_clearance = $security_clearance; |
||
| 78 | $this->language_requirement = $language_requirement; |
||
| 79 | } |
||
| 80 | |||
| 81 | public function jsonSerialize() { |
||
| 82 | $getter_names = get_class_methods(get_class($this)); |
||
| 83 | $gettable_attributes = array(); |
||
| 84 | foreach ($getter_names as $key => $value) { |
||
| 85 | if (substr($value, 0, 3) === 'get') { |
||
| 86 | $gettable_attributes[strtolower(substr($value, 3, strlen($value)))] = $this->$value(); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | return $gettable_attributes; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function getId() { |
||
| 93 | return $this->id; |
||
| 94 | } |
||
| 95 | |||
| 96 | public function getLocale_id() { |
||
| 97 | return $this->locale_id; |
||
| 98 | } |
||
| 99 | |||
| 100 | public function getManager_user_id() { |
||
| 101 | return $this->manager_user_id; |
||
| 102 | } |
||
| 103 | |||
| 104 | public function getTitle() { |
||
| 105 | return $this->title; |
||
| 106 | } |
||
| 107 | |||
| 108 | public function getDescription() { |
||
| 109 | return $this->description; |
||
| 110 | } |
||
| 111 | |||
| 112 | public function getApplicants_to_date() { |
||
| 113 | return $this->applicants_to_date; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function getTerm_qty() { |
||
| 117 | return $this->term_qty; |
||
| 118 | } |
||
| 119 | |||
| 120 | public function getTerm_units() { |
||
| 121 | return $this->term_units; |
||
| 122 | } |
||
| 123 | |||
| 124 | public function getJob_min_level() { |
||
| 125 | return $this->job_min_level; |
||
| 126 | } |
||
| 127 | |||
| 128 | public function getJob_max_level() { |
||
| 129 | return $this->job_max_level; |
||
| 130 | } |
||
| 131 | |||
| 132 | public function getStart_date() { |
||
| 133 | return $this->start_date; |
||
| 134 | } |
||
| 135 | |||
| 136 | public function getOpen_date() { |
||
| 137 | return $this->open_date; |
||
| 138 | } |
||
| 139 | |||
| 140 | public function getClose_date() { |
||
| 141 | return $this->close_date; |
||
| 142 | } |
||
| 143 | |||
| 144 | public function getDepartment() { |
||
| 145 | return $this->department; |
||
| 146 | } |
||
| 147 | |||
| 148 | public function getBranch() { |
||
| 149 | return $this->branch; |
||
| 150 | } |
||
| 151 | |||
| 152 | public function getDivision() { |
||
| 153 | return $this->division; |
||
| 154 | } |
||
| 155 | |||
| 156 | public function getLocation_province() { |
||
| 157 | return $this->location_province; |
||
| 158 | } |
||
| 159 | |||
| 160 | public function getLocation_city() { |
||
| 161 | return $this->location_city; |
||
| 162 | } |
||
| 163 | |||
| 164 | public function getRemuneration_range_low() { |
||
| 165 | return $this->remuneration_range_low; |
||
| 166 | } |
||
| 167 | |||
| 168 | public function getRemuneration_range_high() { |
||
| 169 | return $this->remuneration_range_high; |
||
| 170 | } |
||
| 171 | |||
| 172 | public function getImpact() { |
||
| 174 | } |
||
| 175 | |||
| 176 | public function getKey_tasks() { |
||
| 177 | return $this->key_tasks; |
||
| 178 | } |
||
| 179 | |||
| 180 | public function getCore_competencies() { |
||
| 181 | return $this->core_competencies; |
||
| 182 | } |
||
| 183 | |||
| 184 | public function getDeveloping_competencies() { |
||
| 186 | } |
||
| 187 | |||
| 188 | public function getQuestions() { |
||
| 189 | return $this->questions; |
||
| 190 | } |
||
| 191 | |||
| 192 | public function getNoc() { |
||
| 193 | return $this->noc; |
||
| 194 | } |
||
| 195 | |||
| 196 | public function getClassification() { |
||
| 197 | return $this->classification; |
||
| 198 | } |
||
| 199 | |||
| 200 | public function getSecurity_clearance() { |
||
| 201 | return $this->security_clearance; |
||
| 202 | } |
||
| 203 | |||
| 204 | public function getLanguage_requirement() { |
||
| 205 | return $this->language_requirement; |
||
| 206 | } |
||
| 207 | |||
| 208 | public function setId($id) { |
||
| 209 | $this->id = $id; |
||
| 210 | return $this; |
||
| 211 | } |
||
| 212 | |||
| 213 | public function setLocale_id($locale_id) { |
||
| 214 | $this->locale_id = $locale_id; |
||
| 215 | return $this; |
||
| 216 | } |
||
| 217 | |||
| 218 | public function setManager_user_id($manager_user_id) { |
||
| 219 | $this->manager_user_id = $manager_user_id; |
||
| 220 | return $this; |
||
| 221 | } |
||
| 222 | |||
| 223 | public function setTitle($title) { |
||
| 224 | $this->title = $title; |
||
| 225 | return $this; |
||
| 226 | } |
||
| 227 | |||
| 228 | public function setDescription($description) { |
||
| 229 | $this->description = $description; |
||
| 230 | return $this; |
||
| 231 | } |
||
| 232 | |||
| 233 | public function setApplicants_to_date($applicants_to_date) { |
||
| 234 | $this->applicants_to_date = $applicants_to_date; |
||
| 235 | return $this; |
||
| 236 | } |
||
| 237 | |||
| 238 | public function setTerm_qty($term_qty) { |
||
| 239 | $this->term_qty = $term_qty; |
||
| 240 | return $this; |
||
| 241 | } |
||
| 242 | |||
| 243 | public function setTerm_units($term_units) { |
||
| 244 | $this->term_units = $term_units; |
||
| 245 | return $this; |
||
| 246 | } |
||
| 247 | |||
| 248 | public function setJob_min_level($job_min_level) { |
||
| 249 | $this->job_min_level = $job_min_level; |
||
| 250 | return $this; |
||
| 251 | } |
||
| 252 | |||
| 253 | public function setJob_max_level($job_max_level) { |
||
| 254 | $this->job_max_level = $job_max_level; |
||
| 255 | return $this; |
||
| 256 | } |
||
| 257 | |||
| 258 | public function setStart_date($start_date) { |
||
| 259 | $this->start_date = $start_date; |
||
| 260 | return $this; |
||
| 261 | } |
||
| 262 | |||
| 263 | public function setOpen_date($open_date) { |
||
| 264 | $this->open_date = $open_date; |
||
| 265 | return $this; |
||
| 266 | } |
||
| 267 | |||
| 268 | public function setClose_date($close_date) { |
||
| 269 | $this->close_date = $close_date; |
||
| 270 | return $this; |
||
| 271 | } |
||
| 272 | |||
| 273 | public function setDepartment($department) { |
||
| 274 | $this->department = $department; |
||
| 275 | return $this; |
||
| 276 | } |
||
| 277 | |||
| 278 | public function setBranch($branch) { |
||
| 279 | $this->branch = $branch; |
||
| 280 | return $this; |
||
| 281 | } |
||
| 282 | |||
| 283 | public function setDivision($division) { |
||
| 284 | $this->division = $division; |
||
| 285 | return $this; |
||
| 286 | } |
||
| 287 | |||
| 288 | public function setLocation_province($location_province) { |
||
| 289 | $this->location_province = $location_province; |
||
| 290 | return $this; |
||
| 291 | } |
||
| 292 | |||
| 293 | public function setLocation_city($location_city) { |
||
| 294 | $this->location_city = $location_city; |
||
| 295 | return $this; |
||
| 296 | } |
||
| 297 | |||
| 298 | public function setRemuneration_range_low($remuneration_range_low) { |
||
| 299 | $this->remuneration_range_low = $remuneration_range_low; |
||
| 300 | return $this; |
||
| 301 | } |
||
| 302 | |||
| 303 | public function setRemuneration_range_high($remuneration_range_high) { |
||
| 304 | $this->remuneration_range_high = $remuneration_range_high; |
||
| 305 | return $this; |
||
| 306 | } |
||
| 307 | |||
| 308 | public function setImpact($impact) { |
||
| 309 | $this->impact = $impact; |
||
| 310 | return $this; |
||
| 311 | } |
||
| 312 | |||
| 313 | public function setKey_tasks($key_tasks) { |
||
| 314 | $this->key_tasks = $key_tasks; |
||
| 315 | return $this; |
||
| 316 | } |
||
| 317 | |||
| 318 | public function setCore_competencies($core_competencies) { |
||
| 319 | $this->core_competencies = $core_competencies; |
||
| 320 | return $this; |
||
| 321 | } |
||
| 322 | |||
| 323 | public function setDeveloping_competencies($developing_competencies) { |
||
| 324 | $this->developing_competencies = $developing_competencies; |
||
| 325 | return $this; |
||
| 326 | } |
||
| 327 | |||
| 328 | public function setQuestions($questions) { |
||
| 331 | } |
||
| 332 | |||
| 333 | public function setNoc($noc) { |
||
| 334 | $this->noc = $noc; |
||
| 335 | return $this; |
||
| 336 | } |
||
| 337 | |||
| 338 | public function setClassification($classification) { |
||
| 339 | $this->classification = $classification; |
||
| 340 | return $this; |
||
| 341 | } |
||
| 342 | |||
| 343 | public function setSecurity_clearance($security_clearance) { |
||
| 344 | $this->security_clearance = $security_clearance; |
||
| 345 | return $this; |
||
| 346 | } |
||
| 347 | |||
| 348 | public function setLanguage_requirement($language_requirement) { |
||
| 349 | $this->language_requirement = $language_requirement; |
||
| 350 | return $this; |
||
| 351 | } |
||
| 352 | } |
||
| 353 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.