| Conditions | 10 |
| Paths | 44 |
| Total Lines | 40 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 110 |
| 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 |
||
| 16 | public function show( |
||
| 17 | ?string $slug, |
||
| 18 | Request $request, |
||
| 19 | TranslatorInterface $translator, |
||
| 20 | ParameterBagInterface $params |
||
| 21 | ) { |
||
| 22 | $slug = (null === $slug || '' === $slug) ? 'homepage' : rtrim(strtolower($slug), '/'); |
||
| 23 | $page = $this->getDoctrine() |
||
| 24 | ->getRepository($this->container->getParameter('app.entity_page')) |
||
|
1 ignored issue
–
show
|
|||
| 25 | ->findOneBySlug($slug); |
||
|
1 ignored issue
–
show
|
|||
| 26 | |||
| 27 | // Check if page exist |
||
| 28 | if (null === $page) { |
||
| 29 | throw $this->createNotFoundException(); |
||
| 30 | } |
||
| 31 | |||
| 32 | if (null !== $page->getLocale()) { // avoid bc break, todo remove it |
||
| 33 | $request->setLocale($page->getLocale()); |
||
| 34 | } |
||
| 35 | |||
| 36 | // Check if page is public |
||
| 37 | if ($page->getCreatedAt() > new \DateTimeImmutable() && !$this->isGranted('ROLE_ADMIN')) { |
||
| 38 | throw $this->createNotFoundException(); |
||
| 39 | } |
||
| 40 | |||
| 41 | // SEO redirection if we are not on the good URI (for exemple /fr/tagada instead of /tagada) |
||
| 42 | $redirect = $this->checkIfUriIsCanonical($request, $page); |
||
| 43 | if (false !== $redirect) { |
||
| 44 | return $this->redirect($redirect[0], $redirect[1]); |
||
| 45 | } |
||
| 46 | |||
| 47 | // Maybe the page is a redirection |
||
| 48 | if (false !== $page->getRedirection()) { |
||
| 49 | return $this->redirect($page->getRedirection(), $page->getRedirectionCode()); |
||
| 50 | } |
||
| 51 | |||
| 52 | // method_exists($this->container->getParameter('app.entity_page'), 'getTemplate') && |
||
| 53 | $template = null !== $page->getTemplate() ? $page->getTemplate() : $params->get('app.default_page_template'); |
||
| 54 | |||
| 55 | return $this->render($template, ['page' => $page]); |
||
| 56 | } |
||
| 117 |