| Conditions | 11 |
| Paths | 12 |
| Total Lines | 159 |
| Code Lines | 80 |
| 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 |
||
| 59 | public function leftMenu(FactoryInterface $factory, array $options) |
||
| 60 | { |
||
| 61 | $checker = $this->container->get('security.authorization_checker'); |
||
| 62 | $translator = $this->container->get('translator'); |
||
| 63 | |||
| 64 | $menu = $factory->createItem('root'); |
||
| 65 | $menu->setChildrenAttribute('class', 'nav navbar-nav'); |
||
| 66 | $menu->addChild( |
||
| 67 | $translator->trans('Home'), |
||
| 68 | [ |
||
| 69 | 'route' => 'legacy_index', |
||
| 70 | ] |
||
| 71 | ); |
||
| 72 | |||
| 73 | if ($checker && $checker->isGranted('IS_AUTHENTICATED_FULLY')) { |
||
| 74 | $menu->addChild( |
||
| 75 | $translator->trans('MyCourses'), |
||
| 76 | [ |
||
| 77 | 'route' => 'main', |
||
| 78 | 'routeParameters' => [ |
||
| 79 | 'name' => '../user_portal.php', |
||
| 80 | ], |
||
| 81 | ] |
||
| 82 | ); |
||
| 83 | |||
| 84 | $menu->addChild( |
||
| 85 | $translator->trans('Calendar'), |
||
| 86 | [ |
||
| 87 | 'route' => 'main', |
||
| 88 | 'routeParameters' => [ |
||
| 89 | 'name' => 'calendar/agenda_js.php', |
||
| 90 | ], |
||
| 91 | ] |
||
| 92 | ); |
||
| 93 | |||
| 94 | $menu->addChild( |
||
| 95 | $translator->trans('Reporting'), |
||
| 96 | [ |
||
| 97 | 'route' => 'main', |
||
| 98 | 'routeParameters' => [ |
||
| 99 | 'name' => 'mySpace/index.php', |
||
| 100 | ], |
||
| 101 | ] |
||
| 102 | ); |
||
| 103 | |||
| 104 | $menu->addChild( |
||
| 105 | $translator->trans('Social'), |
||
| 106 | [ |
||
| 107 | 'route' => 'main', |
||
| 108 | 'routeParameters' => [ |
||
| 109 | 'name' => 'social/home.php', |
||
| 110 | ], |
||
| 111 | ] |
||
| 112 | ); |
||
| 113 | |||
| 114 | if ($checker->isGranted('ROLE_ADMIN')) { |
||
| 115 | $menu->addChild( |
||
| 116 | $translator->trans('Dashboard'), |
||
| 117 | [ |
||
| 118 | 'route' => 'main', |
||
| 119 | 'routeParameters' => [ |
||
| 120 | 'name' => 'dashboard/index.php', |
||
| 121 | ], |
||
| 122 | ] |
||
| 123 | ); |
||
| 124 | $menu->addChild( |
||
| 125 | $translator->trans('Administration'), |
||
| 126 | [ |
||
| 127 | 'route' => 'main', |
||
| 128 | 'routeParameters' => [ |
||
| 129 | 'name' => 'admin/index.php', |
||
| 130 | ], |
||
| 131 | ] |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | $categories = $this->container->get('Chamilo\FaqBundle\Repository\CategoryRepository')->retrieveActive(); |
||
| 137 | if ($categories) { |
||
| 138 | $faq = $menu->addChild( |
||
| 139 | 'FAQ', |
||
| 140 | [ |
||
| 141 | 'route' => 'faq_index', |
||
| 142 | ] |
||
| 143 | ); |
||
| 144 | /** @var Category $category */ |
||
| 145 | foreach ($categories as $category) { |
||
| 146 | $faq->addChild( |
||
| 147 | $category->getHeadline(), |
||
| 148 | [ |
||
| 149 | 'route' => 'faq', |
||
| 150 | 'routeParameters' => [ |
||
| 151 | 'categorySlug' => $category->getSlug(), |
||
| 152 | 'questionSlug' => '', |
||
| 153 | ], |
||
| 154 | ] |
||
| 155 | )->setAttribute('divider_append', true); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | // Getting site information |
||
| 160 | $site = $this->container->get('sonata.page.site.selector'); |
||
| 161 | $host = $site->getRequestContext()->getHost(); |
||
| 162 | $siteManager = $this->container->get('sonata.page.manager.site'); |
||
| 163 | /** @var Site $site */ |
||
| 164 | $site = $siteManager->findOneBy([ |
||
| 165 | 'host' => [$host, 'localhost'], |
||
| 166 | 'enabled' => true, |
||
| 167 | ]); |
||
| 168 | |||
| 169 | if ($site) { |
||
| 170 | $pageManager = $this->container->get('sonata.page.manager.page'); |
||
| 171 | |||
| 172 | // Parents only of homepage |
||
| 173 | $criteria = ['site' => $site, 'enabled' => true, 'parent' => 1]; |
||
| 174 | $pages = $pageManager->findBy($criteria); |
||
| 175 | |||
| 176 | //$pages = $pageManager->loadPages($site); |
||
| 177 | /** @var Page $page */ |
||
| 178 | foreach ($pages as $page) { |
||
| 179 | /*if ($page->getRouteName() !== 'page_slug') { |
||
| 180 | continue; |
||
| 181 | }*/ |
||
| 182 | |||
| 183 | // Avoid home |
||
| 184 | if ($page->getUrl() === '/') { |
||
| 185 | continue; |
||
| 186 | } |
||
| 187 | |||
| 188 | if (!$page->isCms()) { |
||
| 189 | continue; |
||
| 190 | } |
||
| 191 | |||
| 192 | $subMenu = $menu->addChild( |
||
| 193 | $page->getName(), |
||
| 194 | [ |
||
| 195 | 'route' => $page->getRouteName(), |
||
| 196 | 'routeParameters' => [ |
||
| 197 | 'path' => $page->getUrl(), |
||
| 198 | ], |
||
| 199 | ] |
||
| 200 | ); |
||
| 201 | |||
| 202 | /** @var Page $child */ |
||
| 203 | foreach ($page->getChildren() as $child) { |
||
| 204 | $subMenu->addChild( |
||
| 205 | $child->getName(), |
||
| 206 | [ |
||
| 207 | 'route' => $page->getRouteName(), |
||
| 208 | 'routeParameters' => [ |
||
| 209 | 'path' => $child->getUrl(), |
||
| 210 | ], |
||
| 211 | ] |
||
| 212 | )->setAttribute('divider_append', true); |
||
| 213 | } |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | return $menu; |
||
| 218 | } |
||
| 220 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.