Completed
Push — master ( 4655cc...858fcc )
by WEBEWEB
01:40
created

AdminBSBRendererTwigExtension::renderIcon()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 33
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.439
c 0
b 0
f 0
cc 5
eloc 16
nc 5
nop 2
1
<?php
2
3
/**
4
 * This file is part of the adminbsb-material-design-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\AdminBSBBundle\Twig\Extension;
13
14
use WBW\Bundle\AdminBSBBundle\Twig\Extension\UI\IconUITwigExtension;
15
use WBW\Bundle\BootstrapBundle\Twig\Extension\BootstrapRendererTwigExtension;
16
17
/**
18
 * AdminBSB renderer Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension
22
 */
23
class AdminBSBRendererTwigExtension extends AbstractAdminBSBTwigExtension {
24
25
    /**
26
     * Render an icon.
27
     *
28
     * @param string $name The icon name.
29
     * @param string $style The icon style.
30
     * @return string Returns a rendered icon.
31
     */
32
    public static function renderIcon($name, $style = null) {
33
34
35
        // Determines the handler.
36
        $handler = explode(":", $name);
37
38
        // Get and check the parse count.
39
        $parseNb = count($handler);
40
        if ($parseNb < 1 || 2 < $parseNb) {
41
            return "";
42
        }
43
        if (1 === count($handler)) {
44
            $handler = ["md", $name];
45
        }
46
47
        // Initialize the output.
48
        $output = "";
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
50
        // Swith into handler.
51
        switch ($handler[0]) {
52
53
            case "md": // Material Design
54
                $output = (new IconUITwigExtension())->renderIcon($handler[1], $style);
55
                break;
56
57
            default:
58
                $output = BootstrapRendererTwigExtension::renderIcon($name, $style);
59
                break;
60
        }
61
62
        // Return the output.
63
        return $output;
64
    }
65
66
}
67