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