Conditions | 11 |
Paths | 180 |
Total Lines | 51 |
Lines | 20 |
Ratio | 39.22 % |
Tests | 0 |
CRAP Score | 132 |
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 |
||
31 | public function renderMenuItemTemplate(Environment $environment, $node, $options = array()) |
||
32 | { |
||
33 | $template = isset($options['template']) ? $options['template'] : false; |
||
34 | if ($template === false) { |
||
35 | $template = '@KunstmaanMenu/menu-item.html.twig'; |
||
36 | } |
||
37 | |||
38 | $hasActiveChild = false; |
||
39 | View Code Duplication | if ($node['__children']) { |
|
|
|||
40 | foreach ($node['__children'] as $childNode) { |
||
41 | if ($childNode['type'] == MenuItem::TYPE_PAGE_LINK) { |
||
42 | $childUrl = $this->router->generate('_slug', array('url' => $childNode['nodeTranslation']['url'])); |
||
43 | if ($this->router->getContext()->getPathInfo() == $childUrl) { |
||
44 | $hasActiveChild = true; |
||
45 | |||
46 | break; |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | |||
52 | $active = false; |
||
53 | View Code Duplication | if ($node['type'] == MenuItem::TYPE_PAGE_LINK) { |
|
54 | $url = $this->router->generate('_slug', array('url' => $node['nodeTranslation']['url'])); |
||
55 | |||
56 | if ($this->router->getContext()->getPathInfo() == $url) { |
||
57 | $active = true; |
||
58 | } |
||
59 | } else { |
||
60 | $url = $node['url']; |
||
61 | } |
||
62 | |||
63 | if ($node['type'] == MenuItem::TYPE_PAGE_LINK) { |
||
64 | if ($node['title']) { |
||
65 | $title = $node['title']; |
||
66 | } else { |
||
67 | $title = $node['nodeTranslation']['title']; |
||
68 | } |
||
69 | } else { |
||
70 | $title = $node['title']; |
||
71 | } |
||
72 | |||
73 | return $environment->render($template, array( |
||
74 | 'menuItem' => $node, |
||
75 | 'url' => $url, |
||
76 | 'options' => $options, |
||
77 | 'title' => $title, |
||
78 | 'active' => $active, |
||
79 | 'hasActiveChild' => $hasActiveChild, |
||
80 | )); |
||
81 | } |
||
82 | } |
||
83 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.