Completed
Push — master ( 10f697...c17cc0 )
by WEBEWEB
02:43
created

AbstractButtonTwigExtension::adminBSBButton()   F

Complexity

Conditions 12
Paths 2048

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 2.8
c 0
b 0
f 0
cc 12
nc 2048
nop 8

How to fix   Complexity    Many Parameters   

Long Method

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:

Many Parameters

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
2
3
/**
4
 * This file is part of the adminbsb-material-design-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\AdminBSBBundle\Twig\Extension\UI;
13
14
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractAdminBSBTwigExtension;
15
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AdminBSBRendererTwigExtension;
16
17
/**
18
 * Abstract button Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension\UI
22
 * @abstract
23
 */
24
abstract class AbstractButtonTwigExtension extends AbstractAdminBSBTwigExtension {
25
26
    /**
27
     * Constructor.
28
     */
29
    protected function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Displays an AdminBSB button.
35
     *
36
     * @param string $content The button content.
37
     * @param string $title The button title.
38
     * @param string $size The button size.
39
     * @param boolean $block Block button ?
40
     * @param booelan $disable Disable button ?
41
     * @param string $class The button class.
42
     * @param string $icon The button icon.
43
     * @param boolean $circle Circle button ?
44
     * @return string Returns the AdminBSB button.
45
     */
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);
0 ignored issues
show
Bug introduced by
The method bootstrapHTMLElement() does not seem to exist on object<WBW\Bundle\AdminB...actButtonTwigExtension>.

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.

Loading history...
73
    }
74
75
}
76