Completed
Push — master ( a2b9d1...d3fba9 )
by WEBEWEB
01:53
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\AdminBSBRendererTwigExtension;
15
use WBW\Bundle\AdminBSBBundle\Twig\Extension\RendererTwigExtension;
16
use WBW\Bundle\BootstrapBundle\Twig\Extension\CSS\ButtonTwigExtension as BaseTwigExtension;
17
18
/**
19
 * Abstract button Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension\UI
23
 * @abstract
24
 */
25
abstract class AbstractButtonTwigExtension extends BaseTwigExtension {
26
27
    /**
28
     * Displays an AdminBSB button.
29
     *
30
     * @param string $content The button content.
31
     * @param string $title The button title.
32
     * @param string $size The button size.
33
     * @param bool $block Block button ?
34
     * @param bool $disable Disable button ?
35
     * @param string $class The button class.
36
     * @param string $icon The button icon.
37
     * @param bool $circle Circle button ?
38
     * @return string Returns the AdminBSB button.
39
     */
40
    protected function adminBSBButton($content, $title, $size, $block, $disable, $class, $icon, $circle) {
41
42
        // Disable the parameters.
43
        $circle = null !== $content ? false : $circle;
44
        $style  = null !== $content ? "margin: -4px 2px 0; vertical-align: sub;" : "";
45
46
        // Initialize the values.
47
        $sizes = ["lg", "sm", "xs"];
48
49
        // Initialize the attributes.
50
        $attributes = [];
51
52
        $attributes["class"]       = ["btn", $class, "waves-effect"];
53
        $attributes["class"][]     = true === $block ? "btn-block" : null;
54
        $attributes["class"][]     = true === $circle ? "btn-circle" . ("lg" === $size ? "-lg" : "") . " waves-circle waves-float" : null;
55
        $attributes["class"][]     = true !== $circle && true === in_array($size, $sizes) ? "btn-" . $size : null;
56
        $attributes["title"]       = $title;
57
        $attributes["type"]        = "button";
58
        $attributes["data-toggle"] = null !== $title ? "tooltip" : null;
59
        $attributes["disabled"]    = true === $disable ? "disabled" : null;
60
61
        // Handle the parameters.
62
        $glyphicon = null !== $icon ? RendererTwigExtension::renderIcon($this->getTwigEnvironment(), $icon, $style) : "";
63
        $innerHTML = null !== $content ? $content : "";
64
65
        // Return the HTML.
66
        return static::coreHTMLElement("button", $glyphicon . $innerHTML, $attributes);
67
    }
68
}
69