| Total Complexity | 74 |
| Total Lines | 576 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Meeting 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 Meeting, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 42 | class Meeting |
||
| 43 | { |
||
| 44 | /** @var string meeting type name */ |
||
| 45 | public $typeName; |
||
| 46 | |||
| 47 | /** @var DateTime meeting start time as a DateTime instance */ |
||
| 48 | public $startDateTime; |
||
| 49 | |||
| 50 | /** @var string meeting formatted start time */ |
||
| 51 | public $formattedStartTime; |
||
| 52 | |||
| 53 | /** @var DateInterval meeting duration as a DateInterval instance */ |
||
| 54 | public $durationInterval; |
||
| 55 | |||
| 56 | /** @var string meeting formatted duration */ |
||
| 57 | public $formattedDuration; |
||
| 58 | |||
| 59 | /** @var string */ |
||
| 60 | public $statusName; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var int |
||
| 64 | * @ORM\Column(type="integer") |
||
| 65 | * @ORM\Id |
||
| 66 | * @ORM\GeneratedValue() |
||
| 67 | */ |
||
| 68 | protected $id; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var int the remote zoom meeting identifier |
||
| 72 | * @ORM\Column(name="meeting_id", type="string") |
||
| 73 | */ |
||
| 74 | protected $meetingId; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var User |
||
| 78 | * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User") |
||
| 79 | * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true) |
||
| 80 | */ |
||
| 81 | protected $user; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var Course |
||
| 85 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course") |
||
| 86 | * @ORM\JoinColumn(name="course_id", referencedColumnName="id", nullable=true) |
||
| 87 | */ |
||
| 88 | protected $course; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var CGroupInfo |
||
| 92 | * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CGroupInfo") |
||
| 93 | * @ORM\JoinColumn(name="group_id", referencedColumnName="iid", nullable=true) |
||
| 94 | */ |
||
| 95 | protected $group; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var Session |
||
| 99 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session") |
||
| 100 | * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true) |
||
| 101 | */ |
||
| 102 | protected $session; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var string |
||
| 106 | * @ORM\Column(type="text", name="meeting_list_item_json", nullable=true) |
||
| 107 | */ |
||
| 108 | protected $meetingListItemJson; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var string |
||
| 112 | * @ORM\Column(type="text", name="meeting_info_get_json", nullable=true) |
||
| 113 | */ |
||
| 114 | protected $meetingInfoGetJson; |
||
| 115 | |||
| 116 | /** @var MeetingListItem */ |
||
| 117 | protected $meetingListItem; |
||
| 118 | |||
| 119 | /** @var MeetingInfoGet */ |
||
| 120 | protected $meetingInfoGet; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var MeetingActivity[]|ArrayCollection |
||
| 124 | * @ORM\OrderBy({"createdAt" = "DESC"}) |
||
| 125 | * @ORM\OneToMany(targetEntity="MeetingActivity", mappedBy="meeting", cascade={"persist", "remove"}) |
||
| 126 | */ |
||
| 127 | protected $activities; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @var Registrant[]|ArrayCollection |
||
| 131 | * |
||
| 132 | * @ORM\OneToMany(targetEntity="Registrant", mappedBy="meeting", cascade={"persist", "remove"}) |
||
| 133 | */ |
||
| 134 | protected $registrants; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @var Recording[]|ArrayCollection |
||
| 138 | * |
||
| 139 | * @ORM\OneToMany(targetEntity="Recording", mappedBy="meeting", cascade={"persist"}, orphanRemoval=true) |
||
| 140 | */ |
||
| 141 | protected $recordings; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var string|null |
||
| 145 | * |
||
| 146 | * @ORM\Column(type="string", name="account_email", nullable=true) |
||
| 147 | */ |
||
| 148 | protected $accountEmail; |
||
| 149 | |||
| 150 | public function __construct() |
||
| 151 | { |
||
| 152 | $this->registrants = new ArrayCollection(); |
||
| 153 | $this->recordings = new ArrayCollection(); |
||
| 154 | $this->activities = new ArrayCollection(); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return string |
||
| 159 | */ |
||
| 160 | public function __toString() |
||
| 161 | { |
||
| 162 | return sprintf('Meeting %d', $this->id); |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return int |
||
| 167 | */ |
||
| 168 | public function getId() |
||
| 169 | { |
||
| 170 | return $this->id; |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @return int |
||
| 175 | */ |
||
| 176 | public function getMeetingId() |
||
| 177 | { |
||
| 178 | return $this->meetingId; |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @param int $meetingId |
||
| 183 | * |
||
| 184 | * @return Meeting |
||
| 185 | */ |
||
| 186 | public function setMeetingId($meetingId) |
||
| 187 | { |
||
| 188 | $this->meetingId = $meetingId; |
||
| 189 | |||
| 190 | return $this; |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return User |
||
| 195 | */ |
||
| 196 | public function getUser() |
||
| 197 | { |
||
| 198 | return $this->user; |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @return Course |
||
| 203 | */ |
||
| 204 | public function getCourse() |
||
| 205 | { |
||
| 206 | return $this->course; |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @return Session |
||
| 211 | */ |
||
| 212 | public function getSession() |
||
| 213 | { |
||
| 214 | return $this->session; |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @return Registrant[]|ArrayCollection |
||
| 219 | */ |
||
| 220 | public function getRegistrants() |
||
| 221 | { |
||
| 222 | return $this->registrants; |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @return Recording[]|ArrayCollection |
||
| 227 | */ |
||
| 228 | public function getRecordings() |
||
| 229 | { |
||
| 230 | return $this->recordings; |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return MeetingActivity[]|ArrayCollection |
||
| 235 | */ |
||
| 236 | public function getActivities() |
||
| 237 | { |
||
| 238 | return $this->activities; |
||
| 239 | } |
||
| 240 | |||
| 241 | public function addActivity(MeetingActivity $activity) |
||
| 242 | { |
||
| 243 | $activity->setMeeting($this); |
||
| 244 | $this->activities[] = $activity; |
||
| 245 | } |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @param MeetingActivity[]|ArrayCollection $activities |
||
| 249 | * |
||
| 250 | * @return Meeting |
||
| 251 | */ |
||
| 252 | public function setActivities($activities) |
||
| 253 | { |
||
| 254 | $this->activities = $activities; |
||
| 255 | |||
| 256 | return $this; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @ORM\PostLoad |
||
| 261 | * |
||
| 262 | * @throws Exception |
||
| 263 | */ |
||
| 264 | public function postLoad() |
||
| 265 | { |
||
| 266 | if (null !== $this->meetingListItemJson) { |
||
| 267 | $this->meetingListItem = MeetingListItem::fromJson($this->meetingListItemJson); |
||
| 268 | } |
||
| 269 | if (null !== $this->meetingInfoGetJson) { |
||
| 270 | $this->meetingInfoGet = MeetingInfoGet::fromJson($this->meetingInfoGetJson); |
||
| 271 | } |
||
| 272 | $this->initializeDisplayableProperties(); |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @ORM\PostUpdate |
||
| 277 | * |
||
| 278 | * @throws Exception |
||
| 279 | */ |
||
| 280 | public function postUpdate() |
||
| 281 | { |
||
| 282 | $this->initializeDisplayableProperties(); |
||
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @ORM\PreFlush |
||
| 287 | */ |
||
| 288 | public function preFlush() |
||
| 289 | { |
||
| 290 | if (null !== $this->meetingListItem) { |
||
| 291 | $this->meetingListItemJson = json_encode($this->meetingListItem); |
||
| 292 | } |
||
| 293 | if (null !== $this->meetingInfoGet) { |
||
| 294 | $this->meetingInfoGetJson = json_encode($this->meetingInfoGet); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @return MeetingListItem |
||
| 300 | */ |
||
| 301 | public function getMeetingListItem() |
||
| 302 | { |
||
| 303 | return $this->meetingListItem; |
||
| 304 | } |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @return MeetingInfoGet |
||
| 308 | */ |
||
| 309 | public function getMeetingInfoGet() |
||
| 310 | { |
||
| 311 | return $this->meetingInfoGet; |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param User $user |
||
| 316 | * |
||
| 317 | * @return $this |
||
| 318 | */ |
||
| 319 | public function setUser($user) |
||
| 320 | { |
||
| 321 | $this->user = $user; |
||
| 322 | |||
| 323 | return $this; |
||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * @param Course $course |
||
| 328 | * |
||
| 329 | * @return $this |
||
| 330 | */ |
||
| 331 | public function setCourse($course) |
||
| 332 | { |
||
| 333 | $this->course = $course; |
||
| 334 | |||
| 335 | return $this; |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @param Session $session |
||
| 340 | * |
||
| 341 | * @return $this |
||
| 342 | */ |
||
| 343 | public function setSession($session) |
||
| 344 | { |
||
| 345 | $this->session = $session; |
||
| 346 | |||
| 347 | return $this; |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @return CGroupInfo |
||
| 352 | */ |
||
| 353 | public function getGroup() |
||
| 354 | { |
||
| 355 | return $this->group; |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @param CGroupInfo $group |
||
| 360 | * |
||
| 361 | * @return Meeting |
||
| 362 | */ |
||
| 363 | public function setGroup($group) |
||
| 364 | { |
||
| 365 | $this->group = $group; |
||
| 366 | |||
| 367 | return $this; |
||
| 368 | } |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @param MeetingListItem $meetingListItem |
||
| 372 | * |
||
| 373 | * @throws Exception |
||
| 374 | * |
||
| 375 | * @return Meeting |
||
| 376 | */ |
||
| 377 | public function setMeetingListItem($meetingListItem) |
||
| 378 | { |
||
| 379 | if (null === $this->meetingId) { |
||
| 380 | $this->meetingId = $meetingListItem->id; |
||
|
|
|||
| 381 | } elseif ($this->meetingId != $meetingListItem->id) { |
||
| 382 | throw new Exception('the Meeting identifier differs from the MeetingListItem identifier'); |
||
| 383 | } |
||
| 384 | $this->meetingListItem = $meetingListItem; |
||
| 385 | |||
| 386 | return $this; |
||
| 387 | } |
||
| 388 | |||
| 389 | /** |
||
| 390 | * @param MeetingInfoGet $meetingInfoGet |
||
| 391 | * |
||
| 392 | * @throws Exception |
||
| 393 | * |
||
| 394 | * @return Meeting |
||
| 395 | */ |
||
| 396 | public function setMeetingInfoGet($meetingInfoGet) |
||
| 397 | { |
||
| 398 | if (null === $this->meetingId) { |
||
| 399 | $this->meetingId = $meetingInfoGet->id; |
||
| 400 | } elseif ($this->meetingId != $meetingInfoGet->id) { |
||
| 401 | throw new Exception('the Meeting identifier differs from the MeetingInfoGet identifier'); |
||
| 402 | } |
||
| 403 | $this->meetingInfoGet = $meetingInfoGet; |
||
| 404 | $this->initializeDisplayableProperties(); |
||
| 405 | |||
| 406 | return $this; |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @return bool |
||
| 411 | */ |
||
| 412 | public function isCourseMeeting() |
||
| 413 | { |
||
| 414 | return null !== $this->course; |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @return bool |
||
| 419 | */ |
||
| 420 | public function isCourseGroupMeeting() |
||
| 423 | } |
||
| 424 | |||
| 425 | /** |
||
| 426 | * @return bool |
||
| 427 | */ |
||
| 428 | public function isUserMeeting() |
||
| 429 | { |
||
| 430 | return null !== $this->user && null === $this->course; |
||
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * @return bool |
||
| 435 | */ |
||
| 436 | public function isGlobalMeeting() |
||
| 439 | } |
||
| 440 | |||
| 441 | public function setStatus($status) |
||
| 442 | { |
||
| 443 | $this->meetingInfoGet->status = $status; |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Builds the list of users that can register into this meeting. |
||
| 448 | * Zoom requires an email address, therefore users without an email address are excluded from the list. |
||
| 449 | * |
||
| 450 | * @return User[] the list of users |
||
| 451 | */ |
||
| 452 | public function getRegistrableUsers() |
||
| 453 | { |
||
| 454 | $users = []; |
||
| 455 | if (!$this->isCourseMeeting()) { |
||
| 456 | $criteria = ['active' => true]; |
||
| 457 | $users = Database::getManager()->getRepository('ChamiloUserBundle:User')->findBy($criteria); |
||
| 458 | } elseif (null === $this->session) { |
||
| 459 | if (null !== $this->course) { |
||
| 460 | /** @var CourseRelUser $courseRelUser */ |
||
| 461 | foreach ($this->course->getUsers() as $courseRelUser) { |
||
| 462 | $users[] = $courseRelUser->getUser(); |
||
| 463 | } |
||
| 464 | } |
||
| 465 | } else { |
||
| 466 | if (null !== $this->course) { |
||
| 467 | $subscriptions = $this->session->getUserCourseSubscriptionsByStatus($this->course, Session::STUDENT); |
||
| 468 | if ($subscriptions) { |
||
| 469 | /** @var SessionRelCourseRelUser $sessionCourseUser */ |
||
| 470 | foreach ($subscriptions as $sessionCourseUser) { |
||
| 471 | $users[] = $sessionCourseUser->getUser(); |
||
| 472 | } |
||
| 473 | } |
||
| 474 | } |
||
| 475 | } |
||
| 476 | |||
| 477 | $activeUsersWithEmail = []; |
||
| 478 | foreach ($users as $user) { |
||
| 479 | if ($user->isActive() && !empty($user->getEmail())) { |
||
| 480 | $activeUsersWithEmail[] = $user; |
||
| 481 | } |
||
| 482 | } |
||
| 483 | |||
| 484 | return $activeUsersWithEmail; |
||
| 485 | } |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @return bool |
||
| 489 | */ |
||
| 490 | public function requiresDateAndDuration() |
||
| 491 | { |
||
| 492 | return MeetingInfoGet::TYPE_SCHEDULED === $this->meetingInfoGet->type |
||
| 493 | || MeetingInfoGet::TYPE_RECURRING_WITH_FIXED_TIME === $this->meetingInfoGet->type; |
||
| 494 | } |
||
| 495 | |||
| 496 | public function requiresRegistration(): bool |
||
| 499 | /*return |
||
| 500 | MeetingSettings::APPROVAL_TYPE_NO_REGISTRATION_REQUIRED != $this->meetingInfoGet->settings->approval_type;*/ |
||
| 501 | } |
||
| 502 | |||
| 503 | /** |
||
| 504 | * @return bool |
||
| 505 | */ |
||
| 506 | public function hasCloudAutoRecordingEnabled() |
||
| 507 | { |
||
| 508 | return \ZoomPlugin::RECORDING_TYPE_NONE !== $this->meetingInfoGet->settings->auto_recording; |
||
| 509 | } |
||
| 510 | |||
| 511 | public function getRegistrantByUser(User $user): ?Registrant |
||
| 522 | } |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Generates a short presentation of the meeting for the future participant. |
||
| 526 | * To be displayed above the "Enter meeting" link. |
||
| 527 | * |
||
| 528 | * @return string |
||
| 529 | */ |
||
| 530 | public function getIntroduction() |
||
| 531 | { |
||
| 532 | $introduction = sprintf('<h1>%s</h1>', $this->getTopic()); |
||
| 555 | } |
||
| 556 | |||
| 557 | public function getAccountEmail(): ?string |
||
| 560 | } |
||
| 561 | |||
| 562 | public function setAccountEmail(?string $accountEmail): self |
||
| 563 | { |
||
| 564 | $this->accountEmail = $accountEmail; |
||
| 565 | |||
| 566 | return $this; |
||
| 567 | } |
||
| 568 | |||
| 569 | public function getTopic(): string |
||
| 570 | { |
||
| 571 | return $this->meetingInfoGet->topic; |
||
| 572 | } |
||
| 573 | |||
| 574 | public function getAgenda(): ?string |
||
| 577 | } |
||
| 578 | |||
| 579 | /** |
||
| 580 | * @throws Exception on unexpected start_time or duration |
||
| 581 | */ |
||
| 582 | protected function initializeDisplayableProperties() |
||
| 618 | } |
||
| 619 | } |
||
| 620 | } |
||
| 621 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.