Completed
Push — master ( 7d0ef3...14c63c )
by WEBEWEB
03:01
created

materialDesignIconicFontIcon()   C

Complexity

Conditions 9
Paths 256

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 6.5222
c 0
b 0
f 0
cc 9
nc 256
nop 9

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 Material Design Iconic Font Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin
22
 * @abstract
23
 */
24
abstract class AbstractMaterialDesignIconicFontTwigExtension extends AbstractBootstrapTwigExtension {
25
26
    /**
27
     * Constructor.
28
     */
29
    protected function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Displays a Material Design Iconic Font icon.
35
     *
36
     * @param string $name The Material Design Iconic Font name.
37
     * @param string $size The Material Design Iconic Font size.
38
     * @param boolean $fixedWidth Fixed width ?
39
     * @param string $border The Material Design Iconic Font border
40
     * @param string $pull The Material Design Iconic Font pull.
41
     * @param string $spin The Material Design Iconic Font spin.
42
     * @param string $rotate The Material Design Iconic Font rotate.
43
     * @param string $flip The Material Design Iconic Font flip.
44
     * @param string $style The Material Design Iconic Font style.
45
     * @return string Returns the Material Design Iconic Font icon.
46
     */
47
    protected function materialDesignIconicFontIcon($name, $size, $fixedWidth, $border, $pull, $spin, $rotate, $flip, $style) {
48
49
        // Initialize the values.
50
        $sizes   = ["lg", "2x", "3x", "4x", "5x"];
51
        $borders = ["border", "border-circle"];
52
        $pulls   = ["left", "right"];
53
        $spins   = ["spin", "spin-reverse"];
54
        $rotates = ["90", "180", "270"];
55
        $flips   = ["horizontal", "vertical"];
56
57
        // Initialize the attributes.
58
        $attributes = [];
59
60
        $attributes["class"][] = "zmdi";
61
        $attributes["class"][] = null !== $name ? "zmdi-" . $name : null;
62
        $attributes["class"][] = true === in_array($size, $sizes) ? "zmdi-hc-" . $size : null;
63
        $attributes["class"][] = true === $fixedWidth ? "zmdi-hc-fw" : null;
64
        $attributes["class"][] = true === in_array($border, $borders) ? "zmdi-hc-" . $border : null;
65
        $attributes["class"][] = true === in_array($pull, $pulls) ? "pull-" . $pull : null;
66
        $attributes["class"][] = true === in_array($spin, $spins) ? "zmdi-hc-" . $spin : null;
67
        $attributes["class"][] = true === in_array($rotate, $rotates) ? "zmdi-hc-rotate-" . $rotate : null;
68
        $attributes["class"][] = true === in_array($flip, $flips) ? "zmdi-hc-flip-" . $flip : null;
69
        $attributes["style"]   = $style;
70
71
        // Return the HTML.
72
        return self::bootstrapHTMLElement("i", null, $attributes);
73
    }
74
75
    /**
76
     * Displays a Material Design Iconic Font list.
77
     *
78
     * @param array|string $items The list items.
79
     * @return string Returns the Material Design Iconic Font list.
80
     */
81
    protected function materialDesignIconicFontList($items) {
82
83
        // Initialize the parameters.
84
        $innerHTML = true === is_array($items) ? implode("\n", $items) : $items;
85
86
        // Return the HTML.
87
        return self::bootstrapHTMLElement("ul", $innerHTML, ["class" => "zmdi-hc-ul"]);
88
    }
89
90
    /**
91
     * Displays a Material Design Iconic Font list icon.
92
     *
93
     * @param string $icon The Material Design Iconic Font icon.
94
     * @param string $content The Material Design Iconic Font content.
95
     * @return string Returns the Material Design Iconic Font list icon.
96
     */
97
    protected function materialDesignIconicFontListIcon($icon, $content) {
98
99
        // Initialize the parameters.
100
        $glyphicon = null !== $icon ? StringUtility::replace($icon, ["class=\"zmdi"], ["class=\"zmdi-hc-li zmdi"]) : "";
101
        $innerHTML = null !== $content ? $content : "";
102
103
        // Return the HTML.
104
        return self::bootstrapHTMLElement("li", $glyphicon . $innerHTML);
105
    }
106
107
}
108