Complex classes like SkillRelUser 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 SkillRelUser, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class SkillRelUser |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * @var integer |
||
| 32 | * |
||
| 33 | * @ORM\Column(name="user_id", type="integer", nullable=false) |
||
| 34 | */ |
||
| 35 | private $userId; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var integer |
||
| 39 | * |
||
| 40 | * @ORM\Column(name="skill_id", type="integer", nullable=false) |
||
| 41 | */ |
||
| 42 | private $skillId; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="achievedSkills", cascade={"persist"}) |
||
| 46 | * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false) |
||
| 47 | */ |
||
| 48 | private $user; |
||
| 49 | /** |
||
| 50 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Skill", inversedBy="issuedSkills", cascade={"persist"}) |
||
| 51 | * @ORM\JoinColumn(name="skill_id", referencedColumnName="id", nullable=false) |
||
| 52 | */ |
||
| 53 | private $skill; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var \DateTime |
||
| 57 | * |
||
| 58 | * @ORM\Column(name="acquired_skill_at", type="datetime", nullable=false) |
||
| 59 | */ |
||
| 60 | private $acquiredSkillAt; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var integer |
||
| 64 | * |
||
| 65 | * @ORM\Column(name="assigned_by", type="integer", nullable=false) |
||
| 66 | */ |
||
| 67 | private $assignedBy; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var integer |
||
| 71 | * |
||
| 72 | * @ORM\Column(name="course_id", type="integer", nullable=false) |
||
| 73 | */ |
||
| 74 | private $courseId; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var integer |
||
| 78 | * |
||
| 79 | * @ORM\Column(name="session_id", type="integer", nullable=false) |
||
| 80 | */ |
||
| 81 | private $sessionId; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="issuedSkills", cascade={"persist"}) |
||
| 85 | * @ORM\JoinColumn(name="course_id", referencedColumnName="id") |
||
| 86 | */ |
||
| 87 | private $course; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", inversedBy="issuedSkills", cascade={"persist"}) |
||
| 91 | * @ORM\JoinColumn(name="session_id", referencedColumnName="id") |
||
| 92 | */ |
||
| 93 | private $session; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var integer |
||
| 97 | * |
||
| 98 | * @ORM\Column(name="id", type="integer") |
||
| 99 | * @ORM\Id |
||
| 100 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
| 101 | */ |
||
| 102 | private $id; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var Level |
||
| 106 | * |
||
| 107 | * @ORM\ManyToOne(targetEntity="Chamilo\SkillBundle\Entity\Level") |
||
| 108 | * @ORM\JoinColumn(name="acquired_level", referencedColumnName="id") |
||
| 109 | */ |
||
| 110 | private $acquiredLevel; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @var string |
||
| 114 | * |
||
| 115 | * @ORM\Column(name="argumentation", type="text") |
||
| 116 | */ |
||
| 117 | private $argumentation; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var integer |
||
| 121 | * |
||
| 122 | * @ORM\Column(name="argumentation_author_id", type="integer") |
||
| 123 | */ |
||
| 124 | private $argumentationAuthorId; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @ORM\OneToMany(targetEntity="SkillRelUserComment", mappedBy="skillRelUser") |
||
| 128 | */ |
||
| 129 | protected $comments; |
||
| 130 | |||
| 131 | public function __construct() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Set userId |
||
| 138 | * |
||
| 139 | * @param integer $userId |
||
| 140 | * @return SkillRelUser |
||
| 141 | */ |
||
| 142 | public function setUserId($userId) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Get userId |
||
| 151 | * |
||
| 152 | * @return integer |
||
| 153 | */ |
||
| 154 | public function getUserId() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Set skillId |
||
| 161 | * |
||
| 162 | * @param integer $skillId |
||
| 163 | * @return SkillRelUser |
||
| 164 | */ |
||
| 165 | public function setSkillId($skillId) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Get skillId |
||
| 174 | * |
||
| 175 | * @return integer |
||
| 176 | */ |
||
| 177 | public function getSkillId() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Set user |
||
| 184 | * @param \Chamilo\UserBundle\Entity\User $user |
||
| 185 | * @return \Chamilo\CoreBundle\Entity\SkillRelUser |
||
| 186 | */ |
||
| 187 | public function setUser(\Chamilo\UserBundle\Entity\User $user) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Get user |
||
| 196 | * @return \Chamilo\UserBundle\Entity\User |
||
| 197 | */ |
||
| 198 | public function getUser() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Set skill |
||
| 205 | * @param \Chamilo\CoreBundle\Entity\Skill $skill |
||
| 206 | * @return \Chamilo\CoreBundle\Entity\SkillRelUser |
||
| 207 | */ |
||
| 208 | public function setSkill(Skill $skill) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Get skill |
||
| 217 | * @return \Chamilo\CoreBundle\Entity\Skill |
||
| 218 | */ |
||
| 219 | public function getSkill() |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Set course |
||
| 226 | * @param \Chamilo\CoreBundle\Entity\Course $course |
||
| 227 | * @return \Chamilo\CoreBundle\Entity\SkillRelUser |
||
| 228 | */ |
||
| 229 | public function setCourse(Course $course) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Get course |
||
| 238 | * @return \Chamilo\CoreBundle\Entity\Course |
||
| 239 | */ |
||
| 240 | public function getCourse() |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Set session |
||
| 247 | * @param \Chamilo\CoreBundle\Entity\Session $session |
||
| 248 | * @return \Chamilo\CoreBundle\Entity\SkillRelUser |
||
| 249 | */ |
||
| 250 | public function setSession(Session $session) |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Get session |
||
| 259 | * @return \Chamilo\CoreBundle\Entity\Session |
||
| 260 | */ |
||
| 261 | public function getSession() |
||
| 265 | |||
| 266 | |||
| 267 | /** |
||
| 268 | * Set acquiredSkillAt |
||
| 269 | * |
||
| 270 | * @param \DateTime $acquiredSkillAt |
||
| 271 | * @return SkillRelUser |
||
| 272 | */ |
||
| 273 | public function setAcquiredSkillAt($acquiredSkillAt) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Get acquiredSkillAt |
||
| 282 | * |
||
| 283 | * @return \DateTime |
||
| 284 | */ |
||
| 285 | public function getAcquiredSkillAt() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Set assignedBy |
||
| 292 | * |
||
| 293 | * @param integer $assignedBy |
||
| 294 | * @return SkillRelUser |
||
| 295 | */ |
||
| 296 | public function setAssignedBy($assignedBy) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Get assignedBy |
||
| 305 | * |
||
| 306 | * @return integer |
||
| 307 | */ |
||
| 308 | public function getAssignedBy() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Set courseId |
||
| 315 | * |
||
| 316 | * @param integer $courseId |
||
| 317 | * @return SkillRelUser |
||
| 318 | */ |
||
| 319 | public function setCourseId($courseId) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Get courseId |
||
| 328 | * |
||
| 329 | * @return integer |
||
| 330 | */ |
||
| 331 | public function getCourseId() |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Set sessionId |
||
| 338 | * |
||
| 339 | * @param integer $sessionId |
||
| 340 | * @return SkillRelUser |
||
| 341 | */ |
||
| 342 | public function setSessionId($sessionId) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Get sessionId |
||
| 351 | * |
||
| 352 | * @return integer |
||
| 353 | */ |
||
| 354 | public function getSessionId() |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Get id |
||
| 361 | * |
||
| 362 | * @return integer |
||
| 363 | */ |
||
| 364 | public function getId() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Set acquiredLevel |
||
| 371 | * @param \Chamilo\SkillBundle\Entity\Level $acquiredLevel |
||
| 372 | * @return \Chamilo\CoreBundle\Entity\SkillRelUser |
||
| 373 | */ |
||
| 374 | public function setAcquiredLevel($acquiredLevel) |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Get acquiredLevel |
||
| 383 | * @return \Chamilo\SkillBundle\Entity\Level |
||
| 384 | */ |
||
| 385 | public function getAcquiredLevel() |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Set argumentationAuthorId |
||
| 392 | * @param integer $argumentationAuthorId |
||
| 393 | * @return \Chamilo\CoreBundle\Entity\SkillRelUser |
||
| 394 | */ |
||
| 395 | public function setArgumentationAuthorId($argumentationAuthorId) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Get argumentationAuthorId |
||
| 404 | * @return integer |
||
| 405 | */ |
||
| 406 | public function getArgumentationAuthorId() |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Set argumentation |
||
| 413 | * @param string $argumentation |
||
| 414 | * @return \Chamilo\CoreBundle\Entity\SkillRelUser |
||
| 415 | */ |
||
| 416 | public function setArgumentation($argumentation) |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Get argumentation |
||
| 425 | * @return string |
||
| 426 | */ |
||
| 427 | public function getArgumentation() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Get the source which the skill was obtained |
||
| 434 | * @return string |
||
| 435 | */ |
||
| 436 | public function getSourceName() |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Get the URL for the issue |
||
| 454 | * @return string |
||
| 455 | */ |
||
| 456 | public function getIssueUrl() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Get the URL for the All issues page |
||
| 463 | * @return string |
||
| 464 | */ |
||
| 465 | public function getIssueUrlAll() |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Get the URL for the assertion |
||
| 472 | * @return string |
||
| 473 | */ |
||
| 474 | public function getAssertionUrl() |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Get comments |
||
| 490 | * @param boolean $sortDescByDateTime |
||
| 491 | * @return ArrayCollection |
||
| 492 | */ |
||
| 493 | public function getComments($sortDescByDateTime = false) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Calculate the average value from the feedback comments |
||
| 509 | * @return type |
||
| 510 | */ |
||
| 511 | public function getAverage() |
||
| 530 | } |
||
| 531 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..