Conditions | 4 |
Paths | 2 |
Total Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Tests | 24 |
CRAP Score | 4 |
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 |
||
43 | 3 | public function render() : string |
|
44 | { |
||
45 | 3 | $output = Module\Hook::trigger('navigationTemplateStart'); |
|
46 | 3 | $outputItem = null; |
|
47 | |||
48 | /* html element */ |
||
49 | |||
50 | 3 | $element = new Html\Element(); |
|
51 | $listElement = $element |
||
52 | 3 | ->copy() |
|
53 | 3 | ->init('ul', |
|
54 | [ |
||
55 | 3 | 'class' => $this->_optionArray['className']['list'] |
|
56 | ]); |
||
57 | 3 | $itemElement = $element->copy()->init('li'); |
|
58 | 3 | $linkElement = $element->copy()->init('a'); |
|
59 | |||
60 | /* template directory */ |
||
61 | |||
62 | 3 | $templateFilesystem = new Filesystem\Filesystem(); |
|
63 | 3 | $templateFilesystem->init('templates', false, |
|
64 | [ |
||
65 | 3 | 'admin', |
|
66 | 'console', |
||
67 | 'install' |
||
68 | ]); |
||
69 | 3 | $templateFilesystemArray = $templateFilesystem->getSortArray(); |
|
70 | |||
71 | /* collect item output */ |
||
72 | |||
73 | 3 | foreach ($templateFilesystemArray as $value) |
|
74 | { |
||
75 | $outputItem .= $itemElement |
||
76 | 3 | ->copy() |
|
77 | 3 | ->addClass($this->_registry->get('template') === $value ? $this->_optionArray['className']['active'] : null) |
|
78 | 3 | ->html($linkElement |
|
79 | 3 | ->copy() |
|
80 | 3 | ->attr( |
|
81 | [ |
||
82 | 3 | 'href' => $this->_registry->get('parameterRoute') . $this->_registry->get('fullRoute') . $this->_registry->get('templateRoute') . $value, |
|
83 | 3 | 'rel' => 'nofollow' |
|
84 | ]) |
||
85 | 3 | ->text($value) |
|
86 | ); |
||
87 | } |
||
88 | |||
89 | /* collect output */ |
||
90 | |||
91 | 3 | $output .= $listElement->html($outputItem ? : $itemElement->text($this->_language->get('template_no'))); |
|
92 | $output .= Module\Hook::trigger('navigationTemplateEnd'); |
||
93 | 3 | return $output; |
|
94 | } |
||
95 | } |
||
96 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.