Complex classes like Cv 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 Cv, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class Cv extends AbstractIdentifiableEntity implements CvInterface, ResourceInterface |
||
| 30 | { |
||
| 31 | use PermissionsAwareTrait, ModificationDateAwareEntityTrait; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Owner of the CV |
||
| 35 | * |
||
| 36 | * @var UserInterface |
||
| 37 | * @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", simple=true, cascade="persist") |
||
| 38 | */ |
||
| 39 | protected $user; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * personal informations, contains firstname, lastname, email, |
||
| 43 | * phone etc. |
||
| 44 | * |
||
| 45 | * @ODM\EmbedOne(targetDocument="Contact") |
||
| 46 | */ |
||
| 47 | protected $contact; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Education History |
||
| 51 | * |
||
| 52 | * @var ArrayCollection |
||
| 53 | * @ODM\EmbedMany(targetDocument="\Cv\Entity\Education") |
||
| 54 | */ |
||
| 55 | protected $educations; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Employment History |
||
| 59 | * |
||
| 60 | * @var ArrayCollection |
||
| 61 | * @ODM\EmbedMany(targetDocument="\Cv\Entity\Employment") |
||
| 62 | */ |
||
| 63 | protected $employments; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Skills |
||
| 67 | * |
||
| 68 | * @var ArrayCollection |
||
| 69 | * @ODM\EmbedMany(targetDocument="\Cv\Entity\Skill") |
||
| 70 | */ |
||
| 71 | protected $skills; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Skills |
||
| 75 | * |
||
| 76 | * @var ArrayCollection |
||
| 77 | * @ODM\EmbedMany(targetDocument="\Cv\Entity\Language") |
||
| 78 | */ |
||
| 79 | protected $languageSkills; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var array |
||
| 83 | * @ODM\Collection |
||
| 84 | */ |
||
| 85 | protected $nativeLanguages=[]; |
||
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * Preferred Job. Where do the user want to work? What kind of work he wants do do |
||
| 90 | * |
||
| 91 | * @ODM\EmbedOne(targetDocument="\Cv\Entity\PreferredJob") |
||
| 92 | */ |
||
| 93 | protected $preferredJob; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Flag indicating draft state of this cv. |
||
| 97 | * |
||
| 98 | * @var bool |
||
| 99 | * @ODM\Boolean |
||
| 100 | */ |
||
| 101 | protected $isDraft = false; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Status |
||
| 105 | * |
||
| 106 | * @var Status |
||
| 107 | * @ODM\EmbedOne(targetDocument="Status") |
||
| 108 | * @ODM\Index |
||
| 109 | */ |
||
| 110 | protected $status; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Multiple attachments |
||
| 114 | * |
||
| 115 | * @since 0.26 |
||
| 116 | * @ODM\ReferenceMany(targetDocument="Attachment", simple="true", cascade={"persist", "remove"}) |
||
| 117 | */ |
||
| 118 | protected $attachments; |
||
| 119 | |||
| 120 | public function __construct() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return UserInterface |
||
| 127 | */ |
||
| 128 | public function getUser() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @param UserInterface $user |
||
| 135 | * @return $this |
||
| 136 | */ |
||
| 137 | public function setUser(UserInterface $user) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Returns the string identifier of the Resource |
||
| 148 | * |
||
| 149 | * @return string |
||
| 150 | */ |
||
| 151 | public function getResourceId() |
||
| 155 | |||
| 156 | |||
| 157 | /** |
||
| 158 | * @return Contact |
||
| 159 | */ |
||
| 160 | public function getContact() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return Cv |
||
| 167 | */ |
||
| 168 | public function setContact(InfoInterface $contact) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @return ArrayCollection |
||
| 179 | */ |
||
| 180 | public function getEducations() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @return ArrayCollection |
||
|
|
|||
| 190 | */ |
||
| 191 | public function getEducationsIndexedById() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @param CollectionInterface $educations |
||
| 198 | * @return $this |
||
| 199 | */ |
||
| 200 | public function setEducations(CollectionInterface $educations) |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @return ArrayCollection |
||
| 208 | */ |
||
| 209 | public function getEmployments() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @return ArrayCollection |
||
| 219 | */ |
||
| 220 | public function getEmploymentsIndexedById() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @param CollectionInterface $employments |
||
| 227 | * @return $this |
||
| 228 | */ |
||
| 229 | public function setEmployments(CollectionInterface $employments) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @return ArrayCollection |
||
| 237 | */ |
||
| 238 | public function getSkills() |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @return ArrayCollection |
||
| 248 | */ |
||
| 249 | public function getSkillsIndexedById() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @param CollectionInterface $skills |
||
| 256 | * @return $this |
||
| 257 | */ |
||
| 258 | public function setSkills(CollectionInterface $skills) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @param bool $isDraft |
||
| 266 | * @return $this |
||
| 267 | */ |
||
| 268 | public function setIsDraft($isDraft) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return boolean |
||
| 276 | */ |
||
| 277 | public function isDraft() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return \Cv\Entity\PreferredJobInterface |
||
| 284 | */ |
||
| 285 | public function getPreferredJob() |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @param \Cv\Entity\PreferredJobInterface $preferredJob |
||
| 295 | * @return $this |
||
| 296 | */ |
||
| 297 | public function setPreferredJob(PreferredJobInterface $preferredJob) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * @return ArrayCollection |
||
| 305 | */ |
||
| 306 | public function getLanguageSkills() |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param CollectionInterface $languageSkills |
||
| 316 | * @return $this |
||
| 317 | */ |
||
| 318 | public function setLanguageSkills(CollectionInterface $languageSkills) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @return ArrayCollection |
||
| 326 | */ |
||
| 327 | public function getLanguageSkillsIndexedById() |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Sets the mothers tongue of the candidate |
||
| 334 | * |
||
| 335 | * @param array |
||
| 336 | * @return $this |
||
| 337 | */ |
||
| 338 | public function setNativeLanguages($nativeLanguages) |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Gets the mothers tongue of the candidate |
||
| 346 | * |
||
| 347 | * @return string |
||
| 348 | */ |
||
| 349 | public function getNativeLanguages() |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return Status |
||
| 356 | */ |
||
| 357 | public function getStatus() |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @param Status|string $status |
||
| 364 | */ |
||
| 365 | public function setStatus($status) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @param CollectionInterface $attachments |
||
| 378 | * @return Cv |
||
| 379 | * @since 0.26 |
||
| 380 | */ |
||
| 381 | public function setAttachments(CollectionInterface $attachments) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * @return CollectionInterface |
||
| 389 | * @since 0.26 |
||
| 390 | */ |
||
| 391 | public function getAttachments() |
||
| 398 | |||
| 399 | /** |
||
| 400 | * |
||
| 401 | * @param PermissionsInterface $permissions |
||
| 402 | */ |
||
| 403 | private function setupPermissions(PermissionsInterface $permissions = null) |
||
| 409 | |||
| 410 | private function updatePermissions($oldUser = null) |
||
| 424 | } |
||
| 425 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.