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

fontAwesomeIcon()   B

Complexity

Conditions 8
Paths 128

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
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
16
/**
17
 * Abstract Font Awesome Twig extension.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin
21
 * @abstract
22
 */
23
abstract class AbstractFontAwesomeTwigExtension extends AbstractBootstrapTwigExtension {
24
25
    /**
26
     * Constructor.
27
     */
28
    protected function __construct() {
29
        parent::__construct();
30
    }
31
32
    /**
33
     * Displays a Font Awesome icon.
34
     *
35
     * @param string $font The Font Awesome font.
36
     * @param string $name The Font Awesome name.
37
     * @param string $size The Font Awesome size.
38
     * @param boolean $fixedWidth Fixed width ?
39
     * @param boolean $bordered Bordered ?
40
     * @param string $pull The Font Awesome pull.
41
     * @param string $anime The Font Awesome animation.
42
     * @param string $style The Font Awesome style.
43
     * @return string Returns the Font Awesome icon.
44
     */
45
    protected function fontAwesomeIcon($font, $name, $size, $fixedWidth, $bordered, $pull, $anime, $style) {
46
47
        // Initialize the values.
48
        $fonts    = ["", "s", "r", "l", "b"];
49
        $sizes    = ["xs", "sm", "lg", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "10x"];
50
        $pulls    = ["left", "right"];
51
        $animates = ["spin", "pulse"];
52
53
        // Initialize the attributes.
54
        $attributes = [];
55
56
        $attributes["class"][] = true === in_array($font, $fonts) ? "fa" . $font : "fa";
57
        $attributes["class"][] = null !== $name ? "fa-" . $name : null;
58
        $attributes["class"][] = true === in_array($size, $sizes) ? "fa-" . $size : null;
59
        $attributes["class"][] = true === $fixedWidth ? "fa-fw" : null;
60
        $attributes["class"][] = true === $bordered ? "fa-border" : null;
61
        $attributes["class"][] = true === in_array($pull, $pulls) ? "fa-pull-" . $pull : null;
62
        $attributes["class"][] = true === in_array($anime, $animates) ? "fa-" . $anime : null;
63
        $attributes["style"]   = $style;
64
65
        // Return the HTML.
66
        return self::bootstrapHTMLElement("i", null, $attributes);
67
    }
68
69
    /**
70
     * Displays a Font Awesome list.
71
     *
72
     * @param array|string $items The list items.
73
     * @return string Returns the Font Awesome list.
74
     */
75
    protected function fontAwesomeList($items) {
76
77
        // Initialize the parameters.
78
        $innerHTML = true === is_array($items) ? implode("\n", $items) : $items;
79
80
        // Return the HTML.
81
        return self::bootstrapHTMLElement("ul", $innerHTML, ["class" => "fa-ul"]);
82
    }
83
84
    /**
85
     * Displays a Font Awesome list icon.
86
     *
87
     * @param string $icon The Font Awesome icon.
88
     * @param string $content The content.
89
     * @return string Returns the Font Awesome list icon.
90
     */
91
    protected function fontAwesomeListIcon($icon, $content) {
92
93
        // Initialize the parameters.
94
        $glyphicon = self::bootstrapHTMLElement("span", $icon, ["class" => "fa-li"]);
95
        $innerHTML = null !== $content ? $content : "";
96
97
        // Return the HTML.
98
        return self::bootstrapHTMLElement("li", $glyphicon . $innerHTML);
99
    }
100
101
}
102