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