Completed
Push — master ( 341a7d...fd15d4 )
by WEBEWEB
02:17
created

AbstractPluginTwigExtension::fontAwesomeIcon()   B

Complexity

Conditions 8
Paths 128

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.2111
c 0
b 0
f 0
cc 8
nc 128
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\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 Font Awesome icon.
35
     *
36
     * @param string $font The Font Awesome font.
37
     * @param string $name The Font Awesome name.
38
     * @param string $size The Font Awesome size.
39
     * @param boolean $fixedWidth Fixed width ?
40
     * @param boolean $bordered Bordered ?
41
     * @param string $pull The Font Awesome pull.
42
     * @param string $anime The Font Awesome animation.
43
     * @param string $style The Font Awesome style.
44
     * @return string Returns the Font Awesome icon.
45
     */
46
    protected function fontAwesomeIcon($font, $name, $size, $fixedWidth, $bordered, $pull, $anime, $style) {
47
48
        // Initialize the values.
49
        $fonts    = ["", "s", "r", "l", "b"];
50
        $sizes    = ["xs", "sm", "lg", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "10x"];
51
        $pulls    = ["left", "right"];
52
        $animates = ["spin", "pulse"];
53
54
        // Initialize the template.
55
        $template = "<i %attributes%></i>";
56
57
        // Initialize the attributes.
58
        $attributes = [];
59
60
        $attributes["class"][] = true === in_array($font, $fonts) ? "fa" . $font : "fa";
61
        $attributes["class"][] = null !== $name ? "fa-" . $name : null;
62
        $attributes["class"][] = true === in_array($size, $sizes) ? "fa-" . $size : null;
63
        $attributes["class"][] = true === $fixedWidth ? "fa-fw" : null;
64
        $attributes["class"][] = true === $bordered ? "fa-border" : null;
65
        $attributes["class"][] = true === in_array($pull, $pulls) ? "fa-pull-" . $pull : null;
66
        $attributes["class"][] = true === in_array($anime, $animates) ? "fa-" . $anime : null;
67
68
        $attributes["style"] = $style;
69
70
        // Return the HTML.
71
        return StringUtility::replace($template, ["%attributes%"], [StringUtility::parseArray($attributes)]);
72
    }
73
74
    /**
75
     * Displays a jQuery input mask.
76
     *
77
     * @param string $selector The input mask selector.
78
     * @param string $mask The input mask.
79
     * @param boolean $scriptTag Script tag ?
80
     * @param array $options The input mask options.
81
     * @return string Returns the jQuery input mask.
82
     */
83
    protected function jQueryInputMask($selector, $mask, $scriptTag, array $options) {
84
85
        // Initialize the template.
86
        $template = ["$('%selector%').inputmask(\"%mask%\",%arguments%);"];
87
        if (true === $scriptTag) {
88
            array_unshift($template, "<script type=\"text/javascript\">");
89
            array_push($template, "</script>");
90
        }
91
92
        // Return the HTML.
93
        return StringUtility::replace(implode("\n", $template), ["%selector%", "%mask%", "%arguments%"], [$selector, $mask, json_encode($options)]);
94
    }
95
96
    /**
97
     * Displays a Material Design Iconic Font icon.
98
     *
99
     * @param string $name The Material Design Iconic Font name.
100
     * @param string $size The Material Design Iconic Font size.
101
     * @param boolean $fixedWidth Fixed width ?
102
     * @param string $border The Material Design Iconic Font border
103
     * @param string $pull The Material Design Iconic Font pull.
104
     * @param string $spin The Material Design Iconic Font spin.
105
     * @param string $rotate The Material Design Iconic Font rotate.
106
     * @param string $flip The Material Design Iconic Font flip.
107
     * @param string $style The Material Design Iconic Font style.
108
     * @return string Returns the Material Design Iconic Font icon.
109
     */
110
    protected function materialDesignIconicFontIcon($name, $size, $fixedWidth, $border, $pull, $spin, $rotate, $flip, $style) {
111
112
        // Initialize the values.
113
        $sizes   = ["lg", "2x", "3x", "4x", "5x"];
114
        $borders = ["border", "border-circle"];
115
        $pulls   = ["left", "right"];
116
        $spins   = ["spin", "spin-reverse"];
117
        $rotates = ["90", "180", "270"];
118
        $flips   = ["horizontal", "vertical"];
119
120
        // Initialize the template.
121
        $template = "<i %attributes%></i>";
122
123
        // Initialize the attributes.
124
        $attributes = [];
125
126
        $attributes["class"][] = "zmdi";
127
        $attributes["class"][] = null !== $name ? "zmdi-" . $name : null;
128
        $attributes["class"][] = true === in_array($size, $sizes) ? "zmdi-hc-" . $size : null;
129
        $attributes["class"][] = true === $fixedWidth ? "zmdi-hc-fw" : null;
130
        $attributes["class"][] = true === in_array($border, $borders) ? "zmdi-hc-" . $border : null;
131
        $attributes["class"][] = true === in_array($pull, $pulls) ? "pull-" . $pull : null;
132
        $attributes["class"][] = true === in_array($spin, $spins) ? "zmdi-hc-" . $spin : null;
133
        $attributes["class"][] = true === in_array($rotate, $rotates) ? "zmdi-hc-rotate-" . $rotate : null;
134
        $attributes["class"][] = true === in_array($flip, $flips) ? "zmdi-hc-flip-" . $flip : null;
135
136
        $attributes["style"] = $style;
137
138
        // Return the HTML.
139
        return StringUtility::replace($template, ["%attributes%"], [StringUtility::parseArray($attributes)]);
140
    }
141
142
}
143