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

AbstractSwitchButtonTwigExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A adminBSBSwitchButton() 0 24 5
1
<?php
2
3
/**
4
 * This file is part of the adminbsb-material-design-bundle package.
5
 *
6
 * (c) 2017 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\Form;
13
14
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractAdminBSBTwigExtension;
15
use WBW\Library\Core\Utility\Argument\StringUtility;
16
17
/**
18
 * Abstract switch button Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Form
22
 * @abstract
23
 */
24
abstract class AbstractSwitchButtonTwigExtension extends AbstractAdminBSBTwigExtension {
25
26
    /**
27
     * Constructor.
28
     */
29
    protected function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Displays an AdminBSB switch button.
35
     *
36
     * @param string $offLabel The off label.
37
     * @param string $name The name.
38
     * @param boolean $checked Checked ?
39
     * @param boolean $disabled Disable ?
40
     * @param string $onLabel The on label.
41
     * @param array $attrs The attributes.
42
     * @param string $class The class.
43
     * @return string Returns the AdminBSB switch button.
44
     */
45
    protected function adminBSBSwitchButton($offLabel, $name, $checked, $disabled, $onLabel, array $attrs, $class) {
46
47
        // Initialize the template.
48
        $template = "<input %attributes%>%innerHTML%";
49
50
        // Initialize the attributes.
51
        $attributes = $attrs;
52
53
        $attributes["name"]     = $name;
54
        $attributes["type"]     = "checkbox";
55
        $attributes["checked"]  = true === $checked ? "checked" : null;
56
        $attributes["disabled"] = true === $disabled ? "disabled" : null;
57
58
        // Initialize the parameters.
59
        $lLabel = null !== $offLabel ? $offLabel : "";
60
        $rLabel = null !== $onLabel ? $onLabel : "";
61
62
        $span  = self::bootstrapHTMLElement("span", null, ["class" => ["lever", $class]]);
0 ignored issues
show
Bug introduced by
The method bootstrapHTMLElement() does not seem to exist on object<WBW\Bundle\AdminB...tchButtonTwigExtension>.

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...
63
        $input = StringUtility::replace($template, ["%attributes%", "%innerHTML%"], [StringUtility::parseArray($attributes), $span]);
64
        $label = self::bootstrapHTMLElement("label", $lLabel . $input . $rLabel);
0 ignored issues
show
Bug introduced by
The method bootstrapHTMLElement() does not seem to exist on object<WBW\Bundle\AdminB...tchButtonTwigExtension>.

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...
65
66
        // Return the HTML.
67
        return self::bootstrapHTMLElement("div", $label, ["class" => "switch"]);
0 ignored issues
show
Bug introduced by
The method bootstrapHTMLElement() does not seem to exist on object<WBW\Bundle\AdminB...tchButtonTwigExtension>.

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...
68
    }
69
70
}
71