| Total Complexity | 50 |
| Total Lines | 537 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 2 | Features | 1 |
Complex classes like CLpItem 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 CLpItem, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class CLpItem |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @ORM\Column(name="iid", type="integer") |
||
| 29 | * @ORM\Id |
||
| 30 | * @ORM\GeneratedValue |
||
| 31 | */ |
||
| 32 | protected ?int $iid = null; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @Assert\NotBlank() |
||
| 36 | * |
||
| 37 | * @ORM\Column(name="title", type="string", length=511, nullable=false) |
||
| 38 | */ |
||
| 39 | protected string $title; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @Assert\NotBlank() |
||
| 43 | * |
||
| 44 | * @ORM\Column(name="item_type", type="string", length=32, nullable=false) |
||
| 45 | */ |
||
| 46 | protected string $itemType; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @ORM\Column(name="ref", type="text", nullable=false) |
||
| 50 | */ |
||
| 51 | protected string $ref; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @ORM\Column(name="description", type="string", length=511, nullable=true) |
||
| 55 | */ |
||
| 56 | protected ?string $description; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @ORM\Column(name="path", type="text", nullable=false) |
||
| 60 | */ |
||
| 61 | protected string $path; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @ORM\Column(name="min_score", type="float", precision=10, scale=0, nullable=false) |
||
| 65 | */ |
||
| 66 | protected float $minScore; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @ORM\Column(name="max_score", type="float", precision=10, scale=0, nullable=true, options={"default":"100"}) |
||
| 70 | */ |
||
| 71 | protected ?float $maxScore; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @ORM\Column(name="mastery_score", type="float", precision=10, scale=0, nullable=true) |
||
| 75 | */ |
||
| 76 | protected ?float $masteryScore = null; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @ORM\Column(name="display_order", type="integer", nullable=false) |
||
| 80 | */ |
||
| 81 | protected int $displayOrder; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @ORM\Column(name="prerequisite", type="text", nullable=true) |
||
| 85 | */ |
||
| 86 | protected ?string $prerequisite = null; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @ORM\Column(name="parameters", type="text", nullable=true) |
||
| 90 | */ |
||
| 91 | protected ?string $parameters = null; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @ORM\Column(name="launch_data", type="text", nullable=false) |
||
| 95 | */ |
||
| 96 | protected string $launchData; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @ORM\Column(name="max_time_allowed", type="string", length=13, nullable=true) |
||
| 100 | */ |
||
| 101 | protected ?string $maxTimeAllowed = null; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @ORM\Column(name="terms", type="text", nullable=true) |
||
| 105 | */ |
||
| 106 | protected ?string $terms = null; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @ORM\Column(name="search_did", type="integer", nullable=true) |
||
| 110 | */ |
||
| 111 | protected ?int $searchDid = null; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @ORM\Column(name="audio", type="string", length=250, nullable=true) |
||
| 115 | */ |
||
| 116 | protected ?string $audio = null; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @ORM\Column(name="prerequisite_min_score", type="float", precision=10, scale=0, nullable=true) |
||
| 120 | */ |
||
| 121 | protected ?float $prerequisiteMinScore = null; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @ORM\Column(name="prerequisite_max_score", type="float", precision=10, scale=0, nullable=true) |
||
| 125 | */ |
||
| 126 | protected ?float $prerequisiteMaxScore = null; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CLp", inversedBy="items", cascade={"persist", "remove"}) |
||
| 130 | * @ORM\JoinColumn(name="lp_id", referencedColumnName="iid") |
||
| 131 | */ |
||
| 132 | protected CLp $lp; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @ORM\ManyToOne(targetEntity="CLpItem", inversedBy="children") |
||
| 136 | * @ORM\JoinColumn(name="parent_item_id", referencedColumnName="iid") |
||
| 137 | */ |
||
| 138 | protected ?CLpItem $parent = null; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @var Collection|CLpItem[] |
||
| 142 | * @ORM\OneToMany(targetEntity="CLpItem", mappedBy="parent") |
||
| 143 | */ |
||
| 144 | protected Collection $children; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @ORM\Column(name="previous_item_id", type="integer", nullable=false) |
||
| 148 | */ |
||
| 149 | protected int $previousItemId; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @ORM\Column(name="next_item_id", type="integer", nullable=false) |
||
| 153 | */ |
||
| 154 | protected int $nextItemId; |
||
| 155 | |||
| 156 | public function __construct() |
||
| 157 | { |
||
| 158 | $this->children = new ArrayCollection(); |
||
| 159 | $this->path = ''; |
||
| 160 | $this->ref = ''; |
||
| 161 | $this->launchData = ''; |
||
| 162 | $this->previousItemId = 0; |
||
| 163 | $this->description = ''; |
||
| 164 | $this->minScore = 0; |
||
| 165 | $this->maxScore = 100.0; |
||
| 166 | } |
||
| 167 | |||
| 168 | public function getIid(): ?int |
||
| 169 | { |
||
| 170 | return $this->iid; |
||
| 171 | } |
||
| 172 | |||
| 173 | public function setLp(CLp $lp): self |
||
| 174 | { |
||
| 175 | $this->lp = $lp; |
||
| 176 | |||
| 177 | return $this; |
||
| 178 | } |
||
| 179 | |||
| 180 | public function getLp(): CLp |
||
| 181 | { |
||
| 182 | return $this->lp; |
||
| 183 | } |
||
| 184 | |||
| 185 | public function setItemType(string $itemType): self |
||
| 186 | { |
||
| 187 | $this->itemType = $itemType; |
||
| 188 | |||
| 189 | return $this; |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Get itemType. |
||
| 194 | * |
||
| 195 | * @return string |
||
| 196 | */ |
||
| 197 | public function getItemType() |
||
| 200 | } |
||
| 201 | |||
| 202 | public function setRef(string $ref): self |
||
| 203 | { |
||
| 204 | $this->ref = $ref; |
||
| 205 | |||
| 206 | return $this; |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Get ref. |
||
| 211 | * |
||
| 212 | * @return string |
||
| 213 | */ |
||
| 214 | public function getRef() |
||
| 215 | { |
||
| 216 | return $this->ref; |
||
| 217 | } |
||
| 218 | |||
| 219 | public function setTitle(string $title): self |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Get title. |
||
| 228 | * |
||
| 229 | * @return string |
||
| 230 | */ |
||
| 231 | public function getTitle() |
||
| 232 | { |
||
| 233 | return $this->title; |
||
| 234 | } |
||
| 235 | |||
| 236 | public function setDescription(string $description): self |
||
| 237 | { |
||
| 238 | $this->description = $description; |
||
| 239 | |||
| 240 | return $this; |
||
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Get description. |
||
| 245 | * |
||
| 246 | * @return string |
||
| 247 | */ |
||
| 248 | public function getDescription() |
||
| 249 | { |
||
| 250 | return $this->description; |
||
| 251 | } |
||
| 252 | |||
| 253 | public function setPath(string $path): self |
||
| 254 | { |
||
| 255 | $this->path = $path; |
||
| 256 | |||
| 257 | return $this; |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Get path. |
||
| 262 | * |
||
| 263 | * @return string |
||
| 264 | */ |
||
| 265 | public function getPath() |
||
| 266 | { |
||
| 267 | return $this->path; |
||
| 268 | } |
||
| 269 | |||
| 270 | public function setMinScore(float $minScore): self |
||
| 271 | { |
||
| 272 | $this->minScore = $minScore; |
||
| 273 | |||
| 274 | return $this; |
||
| 275 | } |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Get minScore. |
||
| 279 | * |
||
| 280 | * @return float |
||
| 281 | */ |
||
| 282 | public function getMinScore() |
||
| 283 | { |
||
| 284 | return $this->minScore; |
||
| 285 | } |
||
| 286 | |||
| 287 | public function setMaxScore(float $maxScore): self |
||
| 288 | { |
||
| 289 | $this->maxScore = $maxScore; |
||
| 290 | |||
| 291 | return $this; |
||
| 292 | } |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Get maxScore. |
||
| 296 | * |
||
| 297 | * @return float |
||
| 298 | */ |
||
| 299 | public function getMaxScore() |
||
| 300 | { |
||
| 301 | return $this->maxScore; |
||
| 302 | } |
||
| 303 | |||
| 304 | public function setMasteryScore(float $masteryScore): self |
||
| 305 | { |
||
| 306 | $this->masteryScore = $masteryScore; |
||
| 307 | |||
| 308 | return $this; |
||
| 309 | } |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Get masteryScore. |
||
| 313 | * |
||
| 314 | * @return float |
||
| 315 | */ |
||
| 316 | public function getMasteryScore() |
||
| 317 | { |
||
| 318 | return $this->masteryScore; |
||
| 319 | } |
||
| 320 | |||
| 321 | public function setPreviousItemId(int $previousItemId): self |
||
| 322 | { |
||
| 323 | $this->previousItemId = $previousItemId; |
||
| 324 | |||
| 325 | return $this; |
||
| 326 | } |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Get previousItemId. |
||
| 330 | * |
||
| 331 | * @return int |
||
| 332 | */ |
||
| 333 | public function getPreviousItemId() |
||
| 334 | { |
||
| 335 | return $this->previousItemId; |
||
| 336 | } |
||
| 337 | |||
| 338 | public function setNextItemId(int $nextItemId): self |
||
| 339 | { |
||
| 340 | $this->nextItemId = $nextItemId; |
||
| 341 | |||
| 342 | return $this; |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Get nextItemId. |
||
| 347 | * |
||
| 348 | * @return int |
||
| 349 | */ |
||
| 350 | public function getNextItemId() |
||
| 351 | { |
||
| 352 | return $this->nextItemId; |
||
| 353 | } |
||
| 354 | |||
| 355 | public function setDisplayOrder(int $displayOrder): self |
||
| 356 | { |
||
| 357 | $this->displayOrder = $displayOrder; |
||
| 358 | |||
| 359 | return $this; |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Get displayOrder. |
||
| 364 | * |
||
| 365 | * @return int |
||
| 366 | */ |
||
| 367 | public function getDisplayOrder() |
||
| 368 | { |
||
| 369 | return $this->displayOrder; |
||
| 370 | } |
||
| 371 | |||
| 372 | public function setPrerequisite(string $prerequisite): self |
||
| 373 | { |
||
| 374 | $this->prerequisite = $prerequisite; |
||
| 375 | |||
| 376 | return $this; |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Get prerequisite. |
||
| 381 | * |
||
| 382 | * @return string |
||
| 383 | */ |
||
| 384 | public function getPrerequisite() |
||
| 385 | { |
||
| 386 | return $this->prerequisite; |
||
| 387 | } |
||
| 388 | |||
| 389 | public function setParameters(string $parameters): self |
||
| 390 | { |
||
| 391 | $this->parameters = $parameters; |
||
| 392 | |||
| 393 | return $this; |
||
| 394 | } |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Get parameters. |
||
| 398 | * |
||
| 399 | * @return string |
||
| 400 | */ |
||
| 401 | public function getParameters() |
||
| 402 | { |
||
| 403 | return $this->parameters; |
||
| 404 | } |
||
| 405 | |||
| 406 | public function setLaunchData(string $launchData): self |
||
| 407 | { |
||
| 408 | $this->launchData = $launchData; |
||
| 409 | |||
| 410 | return $this; |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Get launchData. |
||
| 415 | * |
||
| 416 | * @return string |
||
| 417 | */ |
||
| 418 | public function getLaunchData() |
||
| 419 | { |
||
| 420 | return $this->launchData; |
||
| 421 | } |
||
| 422 | |||
| 423 | public function setMaxTimeAllowed(string $maxTimeAllowed): self |
||
| 424 | { |
||
| 425 | $this->maxTimeAllowed = $maxTimeAllowed; |
||
| 426 | |||
| 427 | return $this; |
||
| 428 | } |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Get maxTimeAllowed. |
||
| 432 | * |
||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | public function getMaxTimeAllowed() |
||
| 436 | { |
||
| 437 | return $this->maxTimeAllowed; |
||
| 438 | } |
||
| 439 | |||
| 440 | public function setTerms(string $terms): self |
||
| 441 | { |
||
| 442 | $this->terms = $terms; |
||
| 443 | |||
| 444 | return $this; |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Get terms. |
||
| 449 | * |
||
| 450 | * @return string |
||
| 451 | */ |
||
| 452 | public function getTerms() |
||
| 453 | { |
||
| 454 | return $this->terms; |
||
| 455 | } |
||
| 456 | |||
| 457 | public function setSearchDid(int $searchDid): self |
||
| 458 | { |
||
| 459 | $this->searchDid = $searchDid; |
||
| 460 | |||
| 461 | return $this; |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Get searchDid. |
||
| 466 | * |
||
| 467 | * @return int |
||
| 468 | */ |
||
| 469 | public function getSearchDid() |
||
| 470 | { |
||
| 471 | return $this->searchDid; |
||
| 472 | } |
||
| 473 | |||
| 474 | public function setAudio(string $audio): self |
||
| 475 | { |
||
| 476 | $this->audio = $audio; |
||
| 477 | |||
| 478 | return $this; |
||
| 479 | } |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Get audio. |
||
| 483 | * |
||
| 484 | * @return string |
||
| 485 | */ |
||
| 486 | public function getAudio() |
||
| 487 | { |
||
| 488 | return $this->audio; |
||
| 489 | } |
||
| 490 | |||
| 491 | public function setPrerequisiteMinScore(float $prerequisiteMinScore): self |
||
| 496 | } |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Get prerequisiteMinScore. |
||
| 500 | * |
||
| 501 | * @return float |
||
| 502 | */ |
||
| 503 | public function getPrerequisiteMinScore() |
||
| 504 | { |
||
| 505 | return $this->prerequisiteMinScore; |
||
| 506 | } |
||
| 507 | |||
| 508 | public function setPrerequisiteMaxScore(float $prerequisiteMaxScore): self |
||
| 509 | { |
||
| 510 | $this->prerequisiteMaxScore = $prerequisiteMaxScore; |
||
| 511 | |||
| 512 | return $this; |
||
| 513 | } |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Get prerequisiteMaxScore. |
||
| 517 | * |
||
| 518 | * @return float |
||
| 519 | */ |
||
| 520 | public function getPrerequisiteMaxScore() |
||
| 521 | { |
||
| 522 | return $this->prerequisiteMaxScore; |
||
| 523 | } |
||
| 524 | |||
| 525 | public function getParentItemId(): int |
||
| 526 | { |
||
| 527 | if (null === $this->parent) { |
||
| 528 | return 0; |
||
| 529 | } |
||
| 530 | |||
| 531 | return $this->getParent()->getIid(); |
||
|
|
|||
| 532 | } |
||
| 533 | |||
| 534 | public function getParent(): ?self |
||
| 535 | { |
||
| 536 | return $this->parent; |
||
| 537 | } |
||
| 538 | |||
| 539 | public function setParent(?self $parent): self |
||
| 544 | } |
||
| 545 | |||
| 546 | /** |
||
| 547 | * @return CLpItem[]|Collection |
||
| 548 | */ |
||
| 549 | public function getChildren() |
||
| 550 | { |
||
| 551 | return $this->children; |
||
| 552 | } |
||
| 553 | |||
| 554 | /** |
||
| 555 | * @param CLpItem[]|Collection $children |
||
| 556 | */ |
||
| 557 | public function setChildren(Collection $children): self |
||
| 558 | { |
||
| 559 | $this->children = $children; |
||
| 560 | |||
| 561 | return $this; |
||
| 562 | } |
||
| 563 | } |
||
| 564 |