| Conditions | 16 |
| Paths | 4 |
| Total Lines | 84 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 67 | public function getAnnouncements(User $user, AccessUrl $url, string $iso): array |
||
| 68 | { |
||
| 69 | $qb = $this->getAnnouncementsQueryBuilder($iso, $url, $user); |
||
| 70 | |||
| 71 | $announcements = $qb->getQuery()->getResult(); |
||
| 72 | $cutSize = 500; |
||
| 73 | $list = []; |
||
| 74 | if (!empty($announcements)) { |
||
| 75 | /** @var SysAnnouncement $announcement */ |
||
| 76 | foreach ($announcements as $announcement) { |
||
| 77 | if ($announcement->hasCareer()) { |
||
| 78 | $promotionList = []; |
||
| 79 | if ($announcement->hasPromotion()) { |
||
| 80 | $promotionList[] = $announcement->getPromotion(); |
||
| 81 | } else { |
||
| 82 | $promotionList = $announcement->getCareer()->getPromotions(); |
||
| 83 | } |
||
| 84 | |||
| 85 | $show = false; |
||
| 86 | foreach ($promotionList as $promotion) { |
||
| 87 | $sessionList = $promotion->getSessions(); |
||
| 88 | foreach ($sessionList as $session) { |
||
| 89 | $subscription = (new SessionRelUser()) |
||
| 90 | ->setUser($user) |
||
| 91 | ->setSession($session) |
||
| 92 | ->setRelationType(0) |
||
| 93 | ; |
||
| 94 | |||
| 95 | // Check student |
||
| 96 | if ($this->security->isGranted('ROLE_STUDENT') && |
||
| 97 | $session->hasUser($subscription) |
||
| 98 | //\SessionManager::isUserSubscribedAsStudent($sessionId, $userId) |
||
| 99 | ) { |
||
| 100 | $show = true; |
||
| 101 | |||
| 102 | break 2; |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($this->security->isGranted('ROLE_TEACHER') && |
||
| 106 | $session->isUserGeneralCoach($user) |
||
| 107 | //SessionManager::user_is_general_coach($userId, $sessionId) |
||
| 108 | ) { |
||
| 109 | $show = true; |
||
| 110 | |||
| 111 | break 2; |
||
| 112 | } |
||
| 113 | |||
| 114 | // Check course coach |
||
| 115 | //$coaches = \SessionManager::getCoachesBySession($sessionId); |
||
| 116 | if ($this->security->isGranted('ROLE_TEACHER') && |
||
| 117 | $session->getSessionRelCourseByUser($user, Session::COACH)->count() > 0 |
||
| 118 | ) { |
||
| 119 | $show = true; |
||
| 120 | |||
| 121 | break 2; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | if (false === $show) { |
||
| 127 | continue; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $announcementData = [ |
||
| 132 | 'id' => $announcement->getId(), |
||
| 133 | 'title' => $announcement->getTitle(), |
||
| 134 | 'content' => $announcement->getContent(), |
||
| 135 | 'readMore' => null, |
||
| 136 | ]; |
||
| 137 | |||
| 138 | if (api_strlen(strip_tags($announcement->getContent())) > $cutSize) { |
||
| 139 | $announcementData['content'] = cut($announcement->getContent(), $cutSize); |
||
| 140 | $announcementData['readMore'] = true; |
||
| 141 | } |
||
| 142 | $list[] = $announcementData; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | if (0 === \count($list)) { |
||
| 147 | return []; |
||
| 148 | } |
||
| 149 | |||
| 150 | return $list; |
||
| 151 | } |
||
| 191 |