Completed
Push — master ( 7d0ef3...14c63c )
by WEBEWEB
03:01
created

AbstractButtonTwigExtension::bootstrapButton()   C

Complexity

Conditions 9
Paths 256

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 6.5222
c 0
b 0
f 0
cc 9
nc 256
nop 8

How to fix   Many Parameters   

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 bootstrap-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\BootstrapBundle\Twig\Extension\CSS;
13
14
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension;
15
use WBW\Bundle\BootstrapBundle\Twig\Extension\BootstrapRendererTwigExtension;
16
17
/**
18
 * Abstract button Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\CSS
22
 * @abstract
23
 */
24
abstract class AbstractButtonTwigExtension extends AbstractBootstrapTwigExtension {
25
26
    /**
27
     * Constructor.
28
     */
29
    protected function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Displays a Bootstrap button.
35
     *
36
     * @param string $content The content.
37
     * @param string $title The title.
38
     * @param string $size The size.
39
     * @param boolean $block Block ?
40
     * @param booelan $active Active ?
41
     * @param booelan $disable Disable ?
42
     * @param string $class The class.
43
     * @param string $icon The icon.
44
     * @return string Returns the Bootstrap button.
45
     */
46
    protected function bootstrapButton($content, $title, $size, $block, $active, $disable, $class, $icon) {
47
48
        // Initialize the attributes.
49
        $attributes = [];
50
51
        $attributes["class"]          = ["btn", $class];
52
        $attributes["class"][]        = true === $block ? "btn-block" : null;
53
        $attributes["class"][]        = true === in_array($size, ["lg", "sm", "xs"]) ? "btn-" . $size : null;
54
        $attributes["class"][]        = true === $active ? "active" : null;
55
        $attributes["title"]          = $title;
56
        $attributes["type"]           = "button";
57
        $attributes["data-toggle"]    = null !== $title ? "tooltip" : null;
58
        $attributes["data-placement"] = null !== $title ? "top" : null;
59
        $attributes["disabled"]       = true === $disable ? "disabled" : null;
60
61
        // Handle the parameters.
62
        $glyphicon = null !== $icon ? BootstrapRendererTwigExtension::renderIcon($icon) : "";
63
        $innerHTML = null !== $content ? $content : "";
64
65
        // Return the HTML.
66
        return self::bootstrapHTMLElement("button", implode(" ", [$glyphicon, $innerHTML]), $attributes);
67
    }
68
69
}
70