Completed
Push — master ( 39998d...6b0e3e )
by WEBEWEB
34:39
created

AbstractPluginTwigExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A bootstrapInputMask() 0 12 2
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\Plugin;
13
14
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension;
15
use WBW\Library\Core\Utility\Argument\StringUtility;
16
17
/**
18
 * Abstract plugin Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin
22
 * @abstract
23
 */
24
abstract class AbstractPluginTwigExtension extends AbstractBootstrapTwigExtension {
25
26
    /**
27
     * Constructor.
28
     */
29
    protected function __construct() {
30
        // NOTHING TO DO.
31
    }
32
33
    /**
34
     * Displays a Bootstrap input mask.
35
     *
36
     * @param string $selector The input mask selector.
37
     * @param string $mask The input mask.
38
     * @param boolean $scriptTag Script tag ?
39
     * @param array $options The input mask options.
40
     * @return string Returns the Bootstrap input mask.
41
     */
42
    protected function bootstrapInputMask($selector, $mask, $scriptTag, array $options) {
43
44
        // Initialize the template.
45
        $template = ["$('%selector%').inputmask(\"%mask%\",%arguments%);"];
46
        if (true === $scriptTag) {
47
            array_unshift($template, "<script type=\"text/javascript\">");
48
            array_push($template, "</script>");
49
        }
50
51
        // Return the HTML.
52
        return StringUtility::replace(implode("\n", $template), ["%selector%", "%mask%", "%arguments%"], [$selector, $mask, json_encode($options)]);
53
    }
54
55
}
56