Conditions | 12 |
Paths | 128 |
Total Lines | 32 |
Lines | 6 |
Ratio | 18.75 % |
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 | public static function getButton(array $link): string |
||
44 | { |
||
45 | $showLabel = $link['showLabel'] ?? false; |
||
46 | $btn = '<div class="c-btn-link btn-group">'; |
||
47 | if (isset($link['href'])) { |
||
48 | $btn .= "<a role=\"button\" href=\"{$link['href']}\" "; |
||
49 | } else { |
||
50 | $btn .= '<button type="button" '; |
||
51 | } |
||
52 | $class = 'btn '; |
||
53 | if (isset($link['class'])) { |
||
54 | $class .= $link['class']; |
||
55 | } |
||
56 | $btn .= "class=\"$class\" "; |
||
57 | if (isset($link['data']) && \is_array($link['data'])) { |
||
58 | foreach ($link['data'] as $key => $value) { |
||
59 | $btn .= "data-{$key}=\"{$value}\" "; |
||
60 | } |
||
61 | } |
||
62 | View Code Duplication | if (!$showLabel && isset($link['label'])) { |
|
63 | $btn .= 'data-placement="top" data-target="focus hover" data-content="' . \App\Language::translate($link['label'], $link['moduleName']) . '" '; |
||
64 | } |
||
65 | $btn .= '>'; |
||
66 | if (isset($link['icon'])) { |
||
67 | $btn .= "<span class=\"{$link['icon']}\"></span>"; |
||
68 | } |
||
69 | View Code Duplication | if ($showLabel && isset($link['label'])) { |
|
70 | $btn .= \App\Language::translate($link['label'], $link['moduleName']); |
||
71 | } |
||
72 | $btn .= isset($link['href']) ? '</a>' : '</button>'; |
||
73 | return $btn . '</div>'; |
||
74 | } |
||
75 | |||
102 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.