AbstractCheckboxTwigExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A adminBSBCheckbox() 0 17 4
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 checkbox Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Form
22
 * @abstract
23
 */
24
abstract class AbstractCheckboxTwigExtension extends AbstractTwigExtension {
25
26
    /**
27
     * Displays a AdminBSB checkbox.
28
     *
29
     * @param string|null $content The content.
30
     * @param string|null $name The name.
31
     * @param string|null $id The id.
32
     * @param bool $checked Checked ?
33
     * @param bool $disabled Disabled ?
34
     * @param bool $filledIn Filled in ?
35
     * @param string|null $class The class.
36
     * @return string Returns the AdminBSB checkbox.
37
     */
38
    protected function adminBSBCheckbox(?string $content, ?string $name, ?string $id, bool $checked, bool $disabled, bool $filledIn, ?string $class): string {
39
40
        $template = "<input %attributes%>%innerHTML%";
41
42
        $attributes = [];
43
44
        $attributes["class"]    = [true === $filledIn ? "filled-in" : null, $class];
45
        $attributes["name"]     = $name;
46
        $attributes["type"]     = "checkbox";
47
        $attributes["id"]       = $id;
48
        $attributes["checked"]  = true === $checked ? "checked" : null;
49
        $attributes["disabled"] = true === $disabled ? "disabled" : null;
50
51
        $innerHTML = static::coreHTMLElement("label", $content, ["for" => $attributes["id"]]);
52
53
        return str_replace(["%attributes%", "%innerHTML%"], [StringHelper::parseArray($attributes), $innerHTML], $template);
54
    }
55
}
56