| Conditions | 11 |
| Paths | 12 |
| Total Lines | 46 |
| Code Lines | 23 |
| 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 |
||
| 25 | public function findAllInCourseByThread( |
||
| 26 | $onlyVisibles, |
||
| 27 | $isAllowedToEdit, |
||
| 28 | CForumThread $thread, |
||
| 29 | Course $course, |
||
| 30 | User $currentUser = null, |
||
| 31 | CGroupInfo $group = null, |
||
| 32 | $orderDirection = 'ASC' |
||
| 33 | ): array { |
||
| 34 | $conditionVisibility = $onlyVisibles ? 'p.visible = 1' : 'p.visible != 2'; |
||
| 35 | $conditionModetared = ''; |
||
| 36 | $filterModerated = true; |
||
| 37 | |||
| 38 | if ( |
||
| 39 | (empty($group) && $isAllowedToEdit) || |
||
| 40 | ( |
||
| 41 | ($group ? $group->userIsTutor($currentUser) : false) || |
||
| 42 | !$onlyVisibles |
||
| 43 | ) |
||
| 44 | ) { |
||
| 45 | $filterModerated = false; |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($filterModerated && $onlyVisibles && $thread->getForum()->isModerated()) { |
||
| 49 | $userId = $currentUser ? $currentUser->getId() : 0; |
||
| 50 | |||
| 51 | $conditionModetared = 'AND p.status = 1 OR |
||
| 52 | (p.status = '.CForumPost::STATUS_WAITING_MODERATION." AND p.posterId = $userId) OR |
||
| 53 | (p.status = ".CForumPost::STATUS_REJECTED." AND p.poster = $userId) OR |
||
| 54 | (p.status IS NULL AND p.posterId = $userId)"; |
||
| 55 | } |
||
| 56 | |||
| 57 | $dql = "SELECT p |
||
| 58 | FROM ChamiloCourseBundle:CForumPost p |
||
| 59 | WHERE |
||
| 60 | p.thread = :thread AND |
||
| 61 | p.cId = :course AND |
||
| 62 | $conditionVisibility |
||
| 63 | $conditionModetared |
||
| 64 | ORDER BY p.iid $orderDirection"; |
||
| 65 | |||
| 66 | return $this |
||
| 67 | ->getEntityManager() |
||
| 68 | ->createQuery($dql) |
||
| 69 | ->setParameters(['thread' => $thread, 'course' => $course]) |
||
| 70 | ->getResult(); |
||
| 71 | } |
||
| 84 |