Completed
Push — master ( fdbfc2...a2832c )
by WEBEWEB
02:08
created

ButtonFactory   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 9
dl 0
loc 154
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A newDangerButton() 0 3 1
A newDefaultButton() 0 3 1
A newInfoButton() 0 3 1
A newLinkButton() 0 3 1
A newPrimaryButton() 0 3 1
A newSuccessButton() 0 3 1
A newWarningButton() 0 3 1
A parseButton() 0 11 1
A parseDangerButton() 0 3 1
A parseDefaultButton() 0 3 1
A parseInfoButton() 0 3 1
A parseLinkButton() 0 3 1
A parsePrimaryButton() 0 3 1
A parseSuccessButton() 0 3 1
A parseWarningButton() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the bootstrap-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\BootstrapBundle\Button;
13
14
use WBW\Library\Core\Argument\ArrayHelper;
15
16
/**
17
 * Button factory.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\BootstrapBundle\Button
21
 */
22
class ButtonFactory {
23
24
    /**
25
     * Creates a new danger button.
26
     *
27
     * @return ButtonInterface Returns the danger button.
28
     */
29
    public static function newDangerButton() {
30
        return new DangerButton();
31
    }
32
33
    /**
34
     * Creates a new default button.
35
     *
36
     * @return ButtonInterface Returns the default button.
37
     */
38
    public static function newDefaultButton() {
39
        return new DefaultButton();
40
    }
41
42
    /**
43
     * Creates a new info button.
44
     *
45
     * @return ButtonInterface Returns the info button.
46
     */
47
    public static function newInfoButton() {
48
        return new InfoButton();
49
    }
50
51
    /**
52
     * Creates a new link button.
53
     *
54
     * @return ButtonInterface Returns the warning button.
55
     */
56
    public static function newLinkButton() {
57
        return new LinkButton();
58
    }
59
60
    /**
61
     * Creates a new primary button.
62
     *
63
     * @return ButtonInterface Returns the primary button.
64
     */
65
    public static function newPrimaryButton() {
66
        return new PrimaryButton();
67
    }
68
69
    /**
70
     * Creates a new success button.
71
     *
72
     * @return ButtonInterface Returns the success button.
73
     */
74
    public static function newSuccessButton() {
75
        return new SuccessButton();
76
    }
77
78
    /**
79
     * Creates a new warning button.
80
     *
81
     * @return ButtonInterface Returns the warning button.
82
     */
83
    public static function newWarningButton() {
84
        return new WarningButton();
85
    }
86
87
    /**
88
     * Parses a button.
89
     *
90
     * @param ButtonInterface $button The button.
91
     * @param array $args The arguments.
92
     * @return ButtonInterface Returns the button.
93
     */
94
    protected static function parseButton(ButtonInterface $button, array $args) {
95
96
        $button->setActive(ArrayHelper::get($args, "active", false));
97
        $button->setBlock(ArrayHelper::get($args, "block", false));
98
        $button->setContent(ArrayHelper::get($args, "content"));
99
        $button->setDisabled(ArrayHelper::get($args, "disabled", false));
100
        $button->setSize(ArrayHelper::get($args, "size"));
101
        $button->setTitle(ArrayHelper::get($args, "title"));
102
103
        return $button;
104
    }
105
106
    /**
107
     * Parse a danger button.
108
     *
109
     * @param array $args The arguments.
110
     * @return ButtonInterface Returns the danger button.
111
     */
112
    public static function parseDangerButton(array $args) {
113
        return static::parseButton(static::newDangerButton(), $args);
114
    }
115
116
    /**
117
     * Parse a default button.
118
     *
119
     * @param array $args The arguments.
120
     * @return ButtonInterface Returns the default button.
121
     */
122
    public static function parseDefaultButton(array $args) {
123
        return static::parseButton(static::newDefaultButton(), $args);
124
    }
125
126
    /**
127
     * Parse a info button.
128
     *
129
     * @param array $args The arguments.
130
     * @return ButtonInterface Returns the info button.
131
     */
132
    public static function parseInfoButton(array $args) {
133
        return static::parseButton(static::newInfoButton(), $args);
134
    }
135
136
    /**
137
     * Parse a link button.
138
     *
139
     * @param array $args The arguments.
140
     * @return ButtonInterface Returns the link button.
141
     */
142
    public static function parseLinkButton(array $args) {
143
        return static::parseButton(static::newLinkButton(), $args);
144
    }
145
146
    /**
147
     * Parse a primary button.
148
     *
149
     * @param array $args The arguments.
150
     * @return ButtonInterface Returns the primary button.
151
     */
152
    public static function parsePrimaryButton(array $args) {
153
        return static::parseButton(static::newPrimaryButton(), $args);
154
    }
155
156
    /**
157
     * Parse a success button.
158
     *
159
     * @param array $args The arguments.
160
     * @return ButtonInterface Returns the success button.
161
     */
162
    public static function parseSuccessButton(array $args) {
163
        return static::parseButton(static::newSuccessButton(), $args);
164
    }
165
166
    /**
167
     * Parse a warning button.
168
     *
169
     * @param array $args The arguments.
170
     * @return ButtonInterface Returns the warning button.
171
     */
172
    public static function parseWarningButton(array $args) {
173
        return static::parseButton(static::newWarningButton(), $args);
174
    }
175
}
176