| Conditions | 11 |
| Paths | 88 |
| Total Lines | 76 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 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 |
||
| 40 | public function indexAction($forumName) |
||
| 41 | { |
||
| 42 | $this->isAuthorised('ROLE_USER'); |
||
| 43 | |||
| 44 | if ($forumName != '~') { |
||
| 45 | $this->isFound($forum = $this->getForumModel()->findOneForumByName($forumName)); |
||
| 46 | } else { |
||
| 47 | $forum = null; |
||
| 48 | } |
||
| 49 | |||
| 50 | $page = $this->getQuery('page', 1); |
||
| 51 | $filter = $this->getQuery('filter', 'all'); |
||
| 52 | // Use this for the sidebar counters |
||
| 53 | $subscriptionForums = $this->getSubscriptionModel()->findAllSubscriptionsForUserById($this->getUser()->getId(), true); |
||
| 54 | $forumsSubscribed = array(); |
||
| 55 | $totalForumsSubscribed = array('count_read' => 0, 'count_unread' => 0, 'count_total' => 0); |
||
| 56 | foreach ($subscriptionForums as $subscription) { |
||
| 57 | $forumSubscribed = $subscription->getForum(); |
||
| 58 | |||
| 59 | if ($forumSubscribed) { |
||
| 60 | $forumSubscribedId = $forumSubscribed->getId(); |
||
| 61 | |||
| 62 | if (! array_key_exists($forumSubscribedId, $forumsSubscribed)) { |
||
| 63 | $forumsSubscribed[$forumSubscribedId] = array( |
||
| 64 | 'forum' => $forumSubscribed, |
||
| 65 | 'count_read' => 0, |
||
| 66 | 'count_unread' => 0, |
||
| 67 | 'count_total' => 0, |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | |||
| 71 | $forumsSubscribed[$forumSubscribedId]['count_total']++; |
||
| 72 | if ($subscription->isRead()) { |
||
| 73 | $forumsSubscribed[$forumSubscribedId]['count_read']++; |
||
| 74 | } else { |
||
| 75 | $forumsSubscribed[$forumSubscribedId]['count_unread']++; |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($forum) { |
||
| 79 | if ($forum->getId() == $forumSubscribedId) { |
||
| 80 | $totalForumsSubscribed['count_total']++; |
||
| 81 | if ($subscription->isRead()) { |
||
| 82 | $totalForumsSubscribed['count_read']++; |
||
| 83 | } else { |
||
| 84 | $totalForumsSubscribed['count_unread']++; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } else { |
||
| 88 | $totalForumsSubscribed['count_total']++; |
||
| 89 | if ($subscription->isRead()) { |
||
| 90 | $totalForumsSubscribed['count_read']++; |
||
| 91 | } else { |
||
| 92 | $totalForumsSubscribed['count_unread']++; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | // Use this for the ALL/READ/UNREAD tab |
||
| 99 | $itemsPerPage = $this->getPageHelper()->getTopicsPerPageOnSubscriptions(); |
||
| 100 | if ($forumName == '~') { |
||
| 101 | $subscriptionPager = $this->getSubscriptionModel()->findAllSubscriptionsPaginatedForUserById($this->getUser()->getId(), $page, $itemsPerPage, $filter, true); |
||
| 102 | } else { |
||
| 103 | $subscriptionPager = $this->getSubscriptionModel()->findAllSubscriptionsPaginatedForUserByIdAndForumById($forum->getId(), $this->getUser()->getId(), $page, $itemsPerPage, $filter, true); |
||
| 104 | } |
||
| 105 | |||
| 106 | return $this->renderResponse('CCDNForumForumBundle:User:Subscription/show.html.', array( |
||
| 107 | 'forum' => $forum, |
||
| 108 | 'forumName' => $forumName, |
||
| 109 | 'subscribed_forums' => $forumsSubscribed, |
||
| 110 | 'total_subscribed_forums' => $totalForumsSubscribed, |
||
| 111 | 'filter' => $filter, |
||
| 112 | 'pager' => $subscriptionPager, |
||
| 113 | 'posts_per_page' => $this->container->getParameter('ccdn_forum_forum.topic.user.show.posts_per_page') |
||
| 114 | )); |
||
| 115 | } |
||
| 116 | |||
| 174 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.