| Conditions | 16 |
| Paths | 4 |
| Total Lines | 85 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | |||
| 73 | $cutSize = 500; |
||
| 74 | $list = []; |
||
| 75 | if (!empty($announcements)) { |
||
| 76 | /** @var SysAnnouncement $announcement */ |
||
| 77 | foreach ($announcements as $announcement) { |
||
| 78 | if ($announcement->hasCareer()) { |
||
| 79 | $promotionList = []; |
||
| 80 | if ($announcement->hasPromotion()) { |
||
| 81 | $promotionList[] = $announcement->getPromotion(); |
||
| 82 | } else { |
||
| 83 | $promotionList = $announcement->getCareer()->getPromotions(); |
||
| 84 | } |
||
| 85 | |||
| 86 | $show = false; |
||
| 87 | foreach ($promotionList as $promotion) { |
||
| 88 | $sessionList = $promotion->getSessions(); |
||
| 89 | foreach ($sessionList as $session) { |
||
| 90 | $subscription = (new SessionRelUser()) |
||
| 91 | ->setUser($user) |
||
| 92 | ->setSession($session) |
||
| 93 | ->setRelationType(0) |
||
| 94 | ; |
||
| 95 | |||
| 96 | // Check student |
||
| 97 | if ($this->security->isGranted('ROLE_STUDENT') && |
||
| 98 | $session->hasUser($subscription) |
||
| 99 | //\SessionManager::isUserSubscribedAsStudent($sessionId, $userId) |
||
| 100 | ) { |
||
| 101 | $show = true; |
||
| 102 | |||
| 103 | break 2; |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($this->security->isGranted('ROLE_TEACHER') && |
||
| 107 | $session->isUserGeneralCoach($user) |
||
| 108 | //SessionManager::user_is_general_coach($userId, $sessionId) |
||
| 109 | ) { |
||
| 110 | $show = true; |
||
| 111 | |||
| 112 | break 2; |
||
| 113 | } |
||
| 114 | |||
| 115 | // Check course coach |
||
| 116 | //$coaches = \SessionManager::getCoachesBySession($sessionId); |
||
| 117 | if ($this->security->isGranted('ROLE_TEACHER') && |
||
| 118 | $session->getSessionRelCourseByUser($user, Session::COACH)->count() > 0 |
||
| 119 | ) { |
||
| 120 | $show = true; |
||
| 121 | |||
| 122 | break 2; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | if (false === $show) { |
||
| 128 | continue; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | $announcementData = [ |
||
| 133 | 'id' => $announcement->getId(), |
||
| 134 | 'title' => $announcement->getTitle(), |
||
| 135 | 'content' => $announcement->getContent(), |
||
| 136 | 'readMore' => null, |
||
| 137 | ]; |
||
| 138 | |||
| 139 | if (api_strlen(strip_tags($announcement->getContent())) > $cutSize) { |
||
| 140 | $announcementData['content'] = cut($announcement->getContent(), $cutSize); |
||
| 141 | $announcementData['readMore'] = true; |
||
| 142 | } |
||
| 143 | $list[] = $announcementData; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | if (0 === \count($list)) { |
||
| 148 | return []; |
||
| 149 | } |
||
| 150 | |||
| 151 | return $list; |
||
| 152 | } |
||
| 207 |