Conditions | 12 |
Paths | 2048 |
Total Lines | 28 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
46 | protected function adminBSBButton($content, $title, $size, $block, $disable, $class, $icon, $circle) { |
||
47 | |||
48 | // Disable the parameters. |
||
49 | $circle = null !== $content ? false : $circle; |
||
50 | $style = null !== $content ? "margin: -4px 2px 0; vertical-align: sub;" : ""; |
||
51 | |||
52 | // Initialize the values. |
||
53 | $sizes = ["lg", "sm", "xs"]; |
||
54 | |||
55 | // Initialize the attributes. |
||
56 | $attributes = []; |
||
57 | |||
58 | $attributes["class"] = ["btn", $class, "waves-effect"]; |
||
59 | $attributes["class"][] = true === $block ? "btn-block" : null; |
||
60 | $attributes["class"][] = true === $circle ? "btn-circle" . ("lg" === $size ? "-lg" : "") . " waves-circle waves-float" : null; |
||
61 | $attributes["class"][] = true !== $circle && true === in_array($size, $sizes) ? "btn-" . $size : null; |
||
62 | $attributes["title"] = $title; |
||
63 | $attributes["type"] = "button"; |
||
64 | $attributes["data-toggle"] = null !== $title ? "tooltip" : null; |
||
65 | $attributes["disabled"] = true === $disable ? "disabled" : null; |
||
66 | |||
67 | // Handle the parameters. |
||
68 | $innerHTML = null !== $content ? $content : ""; |
||
69 | $glyphicon = null !== $icon ? AdminBSBRendererTwigExtension::renderIcon($icon, $style) : ""; |
||
70 | |||
71 | // Return the HTML. |
||
72 | return self::bootstrapHTMLElement("button", $glyphicon . $innerHTML, $attributes); |
||
|
|||
73 | } |
||
74 | |||
76 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.