IconFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 24
dl 0
loc 65
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A newFontAwesomeIcon() 0 2 1
A parseFontAwesomeIcon() 0 15 1
A parseMaterialDesignIconicFontIcon() 0 16 1
A newMaterialDesignIconicFontIcon() 0 2 1
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2019 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\Factory;
13
14
use WBW\Bundle\CoreBundle\Assets\Icon\FontAwesomeIcon;
15
use WBW\Bundle\CoreBundle\Assets\Icon\FontAwesomeIconInterface;
16
use WBW\Bundle\CoreBundle\Assets\Icon\MaterialDesignIconicFontIcon;
17
use WBW\Bundle\CoreBundle\Assets\Icon\MaterialDesignIconicFontIconInterface;
18
use WBW\Library\Types\Helper\ArrayHelper;
19
20
/**
21
 * Icon factory.
22
 *
23
 * @author webeweb <https://github.com/webeweb>
24
 * @package WBW\Bundle\CoreBundle\Factory
25
 */
26
class IconFactory {
27
28
    /**
29
     * Create a Font Awesome icon.
30
     *
31
     * @return FontAwesomeIconInterface Returns the Font Awesome icon.
32
     */
33
    public static function newFontAwesomeIcon(): FontAwesomeIconInterface {
34
        return new FontAwesomeIcon();
35
    }
36
37
    /**
38
     * Create a Material Design Iconic Font icon.
39
     *
40
     * @return MaterialDesignIconicFontIconInterface Returns the Material Design Iconic Font icon.
41
     */
42
    public static function newMaterialDesignIconicFontIcon(): MaterialDesignIconicFontIconInterface {
43
        return new MaterialDesignIconicFontIcon();
44
    }
45
46
    /**
47
     * Parse a Font Awesome icon.
48
     *
49
     * @param array $args The arguments.
50
     * @return FontAwesomeIconInterface Returns the parsed Font Awesome icon.
51
     */
52
    public static function parseFontAwesomeIcon(array $args): FontAwesomeIconInterface {
53
54
        $icon = static::newFontAwesomeIcon();
55
56
        $icon->setName(ArrayHelper::get($args, "name", "home"));
57
        $icon->setStyle(ArrayHelper::get($args, "style"));
58
59
        $icon->setAnimation(ArrayHelper::get($args, "animation"));
60
        $icon->setBordered(ArrayHelper::get($args, "bordered", false));
61
        $icon->setFixedWidth(ArrayHelper::get($args, "fixedWidth", false));
62
        $icon->setFont(ArrayHelper::get($args, "font"));
63
        $icon->setPull(ArrayHelper::get($args, "pull"));
64
        $icon->setSize(ArrayHelper::get($args, "size"));
65
66
        return $icon;
67
    }
68
69
    /**
70
     * Parse a Material Design Iconic Font icon.
71
     *
72
     * @param array $args The arguments.
73
     * @return MaterialDesignIconicFontIconInterface Returns the parsed Material Design Iconic Font icon.
74
     */
75
    public static function parseMaterialDesignIconicFontIcon(array $args): MaterialDesignIconicFontIconInterface {
76
77
        $icon = static::newMaterialDesignIconicFontIcon();
78
79
        $icon->setName(ArrayHelper::get($args, "name", "home"));
80
        $icon->setStyle(ArrayHelper::get($args, "style"));
81
82
        $icon->setBorder(ArrayHelper::get($args, "border", false));
0 ignored issues
show
Bug introduced by
It seems like WBW\Library\Types\Helper...$args, 'border', false) can also be of type false; however, parameter $border of WBW\Bundle\CoreBundle\As...icFontIcon::setBorder() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
        $icon->setBorder(/** @scrutinizer ignore-type */ ArrayHelper::get($args, "border", false));
Loading history...
83
        $icon->setFixedWidth(ArrayHelper::get($args, "fixedWidth", false));
84
        $icon->setFlip(ArrayHelper::get($args, "flip"));
85
        $icon->setPull(ArrayHelper::get($args, "pull"));
86
        $icon->setRotate(ArrayHelper::get($args, "rotate"));
87
        $icon->setSize(ArrayHelper::get($args, "size"));
88
        $icon->setSpin(ArrayHelper::get($args, "spin"));
89
90
        return $icon;
91
    }
92
}
93