AbstractSwitchButtonTwigExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A adminBSBSwitchButton() 0 20 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\AbstractTwigExtension;
15
use WBW\Library\Core\Argument\Helper\StringHelper;
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 AbstractTwigExtension {
25
26
    /**
27
     * Displays an AdminBSB switch button.
28
     *
29
     * @param string|null $offLabel The off label.
30
     * @param string|null $name The name.
31
     * @param bool $checked Checked ?
32
     * @param bool $disabled Disable ?
33
     * @param string|null $onLabel The on label.
34
     * @param array $attrs The attributes.
35
     * @param string|null $class The class.
36
     * @return string Returns the AdminBSB switch button.
37
     */
38
    protected function adminBSBSwitchButton(?string $offLabel, ?string $name, bool $checked, bool $disabled, ?string $onLabel, array $attrs, ?string $class): string {
39
40
        $template = "<input %attributes%>%innerHTML%";
41
42
        $attributes = $attrs;
43
44
        $attributes["name"]     = $name;
45
        $attributes["type"]     = "checkbox";
46
        $attributes["checked"]  = true === $checked ? "checked" : null;
47
        $attributes["disabled"] = true === $disabled ? "disabled" : null;
48
49
        $lLabel = null !== $offLabel ? $offLabel : "";
50
        $rLabel = null !== $onLabel ? $onLabel : "";
51
52
        $span  = static::coreHTMLElement("span", null, ["class" => ["lever", $class]]);
53
        $input = str_replace(["%attributes%", "%innerHTML%"], [StringHelper::parseArray($attributes), $span], $template);
54
        $label = static::coreHTMLElement("label", $lLabel . $input . $rLabel);
55
56
        return static::coreHTMLElement("div", $label, ["class" => "switch"]);
57
    }
58
}
59