Completed
Push — develop ( efbf23...556e46 )
by Paul
02:08
created
src/Form.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 */
34 34
 	protected $normalize;
35 35
 
36
-	public function __construct( Field $field, Normalizer $normalize )
36
+	public function __construct(Field $field, Normalizer $normalize)
37 37
 	{
38 38
 		$this->args         = [];
39 39
 		$this->dependencies = [];
@@ -48,15 +48,15 @@  discard block
 block discarded – undo
48 48
 	 * @return mixed
49 49
 	 * @throws Exception
50 50
 	 */
51
-	public function __get( $property )
51
+	public function __get($property)
52 52
 	{
53
-		switch( $property ) {
53
+		switch ($property) {
54 54
 			case 'args';
55 55
 			case 'dependencies';
56 56
 			case 'fields';
57 57
 			return $this->$property;
58 58
 		}
59
-		throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property ));
59
+		throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property));
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
 	 * @return void
67 67
 	 * @throws Exception
68 68
 	 */
69
-	public function __set( $property, $value )
69
+	public function __set($property, $value)
70 70
 	{
71
-		switch( $property ) {
71
+		switch ($property) {
72 72
 			case 'args':
73 73
 			case 'dependencies':
74 74
 			case 'fields':
75 75
 				$this->$property = $value;
76 76
 				break;
77 77
 			default:
78
-				throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property ));
78
+				throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property));
79 79
 		}
80 80
 	}
81 81
 
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @return Form
86 86
 	 */
87
-	public function addField( array $args = [] )
87
+	public function addField(array $args = [])
88 88
 	{
89
-		$field = $this->field->normalize( $args );
89
+		$field = $this->field->normalize($args);
90 90
 
91
-		if( $field->args['render'] !== false ) {
91
+		if ($field->args['render'] !== false) {
92 92
 			$this->dependencies = array_unique(
93
-				array_merge( $field->dependencies, $this->dependencies )
93
+				array_merge($field->dependencies, $this->dependencies)
94 94
 			);
95 95
 			$this->fields[] = $field;
96 96
 		}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @return Form
105 105
 	 */
106
-	public function normalize( array $args = [] )
106
+	public function normalize(array $args = [])
107 107
 	{
108 108
 		$defaults = [
109 109
 			'action'     => '',
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 			'enctype'    => 'multipart/form-data',
114 114
 			'method'     => 'post',
115 115
 			'nonce'      => '',
116
-			'submit'     => __( 'Submit', 'site-reviews' ),
116
+			'submit'     => __('Submit', 'site-reviews'),
117 117
 		];
118 118
 
119
-		$this->args = array_merge( $defaults, $args );
119
+		$this->args = array_merge($defaults, $args);
120 120
 
121
-		$attributes = $this->normalize->form( $this->args, 'implode' );
121
+		$attributes = $this->normalize->form($this->args, 'implode');
122 122
 
123 123
 		$this->args['attributes'] = $attributes;
124 124
 
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
 	 *
133 133
 	 * @return string|void
134 134
 	 */
135
-	public function render( $print = true )
135
+	public function render($print = true)
136 136
 	{
137
-		$rendered = sprintf( '<form %s>%s%s</form>',
137
+		$rendered = sprintf('<form %s>%s%s</form>',
138 138
 			$this->args['attributes'],
139 139
 			$this->generateFields(),
140 140
 			$this->generateSubmitButton()
141 141
 		);
142 142
 
143
-		if( !!$print && $print !== 'return' ) {
143
+		if (!!$print && $print !== 'return') {
144 144
 			echo $rendered;
145 145
 		}
146 146
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	{
170 170
 		$hiddenFields = '';
171 171
 
172
-		$fields = array_reduce( $this->fields, function( $carry, $formField ) use ( &$hiddenFields ) {
172
+		$fields = array_reduce($this->fields, function($carry, $formField) use (&$hiddenFields) {
173 173
 
174 174
 			$stringLegend    = '<legend class="screen-reader-text"><span>%s</span></legend>';
175 175
 			$stringFieldset  = '<fieldset%s>%s%s</fieldset>';
@@ -185,30 +185,30 @@  discard block
 block discarded – undo
185 185
 			$rendered = $field->render();
186 186
 
187 187
 			// render hidden inputs outside the table
188
-			if( $field->args['type'] === 'hidden' ) {
188
+			if ($field->args['type'] === 'hidden') {
189 189
 				$hiddenFields .= $rendered;
190 190
 				return $carry;
191 191
 			}
192 192
 
193
-			$hiddenClass = $this->isFieldHidden( $formField ) ? 'hidden' : '';
193
+			$hiddenClass = $this->isFieldHidden($formField) ? 'hidden' : '';
194 194
 
195
-			if( $multi ) {
196
-				if( $depends = $formField->getDataDepends() ) {
197
-					$depends = sprintf( ' data-depends=\'%s\'', json_encode( $depends ));
195
+			if ($multi) {
196
+				if ($depends = $formField->getDataDepends()) {
197
+					$depends = sprintf(' data-depends=\'%s\'', json_encode($depends));
198 198
 				}
199 199
 
200
-				$legend = $label ? sprintf( $stringLegend, $label ) : '';
201
-				$rendered = sprintf( $stringFieldset, $depends, $legend, $rendered );
200
+				$legend = $label ? sprintf($stringLegend, $label) : '';
201
+				$rendered = sprintf($stringFieldset, $depends, $legend, $rendered);
202 202
 			}
203 203
 
204 204
 			$renderedField = $field->outside
205
-				? sprintf( $outsideRendered, $rendered )
206
-				: sprintf( $stringRendered, $hiddenClass, $label, $rendered );
205
+				? sprintf($outsideRendered, $rendered)
206
+				: sprintf($stringRendered, $hiddenClass, $label, $rendered);
207 207
 
208 208
 			return $carry . $renderedField;
209 209
 		});
210 210
 
211
-		return sprintf( '<table class="form-table"><tbody>%s</tbody></table>%s', $fields, $hiddenFields );
211
+		return sprintf('<table class="form-table"><tbody>%s</tbody></table>%s', $fields, $hiddenFields);
212 212
 	}
213 213
 
214 214
 	/**
@@ -220,19 +220,19 @@  discard block
 block discarded – undo
220 220
 	{
221 221
 		$args = $this->args['submit'];
222 222
 
223
-		is_array( $args ) ?: $args = ['text' => $args ];
223
+		is_array($args) ?: $args = ['text' => $args];
224 224
 
225 225
 		$args = shortcode_atts([
226
-			'text' => __( 'Save Changes', 'site-reviews' ),
226
+			'text' => __('Save Changes', 'site-reviews'),
227 227
 			'type' => 'primary',
228 228
 			'name' => 'submit',
229 229
 			'wrap' => true,
230 230
 			'other_attributes' => null,
231
-		], $args );
231
+		], $args);
232 232
 
233
-		if( is_admin() ) {
233
+		if (is_admin()) {
234 234
 			ob_start();
235
-			submit_button( $args['text'], $args['type'], $args['name'], $args['wrap'], $args['other_attributes'] );
235
+			submit_button($args['text'], $args['type'], $args['name'], $args['wrap'], $args['other_attributes']);
236 236
 			return ob_get_clean();
237 237
 		}
238 238
 	}
@@ -242,15 +242,15 @@  discard block
 block discarded – undo
242 242
 	 *
243 243
 	 * @return bool|null
244 244
 	 */
245
-	protected function isFieldHidden( $field )
245
+	protected function isFieldHidden($field)
246 246
 	{
247
-		if( !( $dependsOn = $field->getDataDepends() ))return;
247
+		if (!($dependsOn = $field->getDataDepends()))return;
248 248
 
249
-		foreach( $this->fields as $formField ) {
250
-			if( $dependsOn['name'] !== $formField->args['name'] )continue;
249
+		foreach ($this->fields as $formField) {
250
+			if ($dependsOn['name'] !== $formField->args['name'])continue;
251 251
 
252
-			if( is_array( $dependsOn['value'] )) {
253
-				return !in_array( $formField->args['value'], $dependsOn['value'] );
252
+			if (is_array($dependsOn['value'])) {
253
+				return !in_array($formField->args['value'], $dependsOn['value']);
254 254
 			}
255 255
 
256 256
 			return $dependsOn['value'] != $formField->args['value'];
Please login to merge, or discard this patch.
src/Forms/Form.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 {
9 9
 	public $field;
10 10
 
11
-	public function __construct( Field $field )
11
+	public function __construct(Field $field)
12 12
 	{
13 13
 		$this->field = $field;
14 14
 	}
Please login to merge, or discard this patch.
src/Forms/Fields/Checkbox.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@  discard block
 block discarded – undo
8 8
 {
9 9
 	protected $element = 'input';
10 10
 
11
-	public function __construct( array $args = [] )
11
+	public function __construct(array $args = [])
12 12
 	{
13
-		parent::__construct( $args );
13
+		parent::__construct($args);
14 14
 
15
-		if( count( $args['options'] ) > 1 ) {
15
+		if (count($args['options']) > 1) {
16 16
 			$this->multi = true;
17 17
 		}
18 18
 	}
@@ -24,16 +24,16 @@  discard block
 block discarded – undo
24 24
 	{
25 25
 		$inline = $this->args['inline'] ? ' class="inline"' : '';
26 26
 
27
-		if( $this->multi ) {
28
-			return sprintf( '<ul%s>%s</ul>%s',
27
+		if ($this->multi) {
28
+			return sprintf('<ul%s>%s</ul>%s',
29 29
 				$inline,
30
-				$this->implodeOptions( 'multi_input_checkbox' ),
30
+				$this->implodeOptions('multi_input_checkbox'),
31 31
 				$this->generateDescription()
32 32
 			);
33 33
 		}
34 34
 
35
-		return sprintf( '%s%s',
36
-			$this->implodeOptions( 'single_input' ),
35
+		return sprintf('%s%s',
36
+			$this->implodeOptions('single_input'),
37 37
 			$this->generateDescription()
38 38
 		);
39 39
 	}
Please login to merge, or discard this patch.
src/Forms/Fields/Radio.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@
 block discarded – undo
11 11
 	/**
12 12
 	 * @return string
13 13
 	 */
14
-	public function render( $default = null )
14
+	public function render($default = null)
15 15
 	{
16 16
 		$inline = $this->args['inline'] ? ' class="inline"' : '';
17 17
 
18
-		return sprintf( '<ul%s>%s</ul>%s',
18
+		return sprintf('<ul%s>%s</ul>%s',
19 19
 			$inline,
20
-			$this->implodeOptions( 'multi_input', $default ),
20
+			$this->implodeOptions('multi_input', $default),
21 21
 			$this->generateDescription()
22 22
 		);
23 23
 	}
Please login to merge, or discard this patch.
src/Forms/Fields/Submit.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
 	 */
12 12
 	public function render()
13 13
 	{
14
-		if( isset( $this->args['name'] )) {
14
+		if (isset($this->args['name'])) {
15 15
 			$this->args['name'] = 'submit';
16 16
 		}
17 17
 
Please login to merge, or discard this patch.
src/Forms/Fields/Select.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@
 block discarded – undo
11 11
 	/**
12 12
 	 * @return string
13 13
 	 */
14
-	public function render( array $defaults = [] )
14
+	public function render(array $defaults = [])
15 15
 	{
16
-		$defaults = wp_parse_args( $defaults, [
16
+		$defaults = wp_parse_args($defaults, [
17 17
 			'type' => 'select',
18 18
 		]);
19 19
 
20
-		return sprintf( '<select %s>%s</select>%s',
21
-			$this->implodeAttributes( $defaults ),
22
-			$this->implodeOptions( 'select_option' ),
20
+		return sprintf('<select %s>%s</select>%s',
21
+			$this->implodeAttributes($defaults),
22
+			$this->implodeOptions('select_option'),
23 23
 			$this->generateDescription()
24 24
 		);
25 25
 	}
Please login to merge, or discard this patch.
src/Forms/Fields/Hidden.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,16 +11,16 @@
 block discarded – undo
11 11
 	 */
12 12
 	public function render()
13 13
 	{
14
-		if( isset( $this->args['label'] )) {
15
-			unset( $this->args['label'] );
14
+		if (isset($this->args['label'])) {
15
+			unset($this->args['label']);
16 16
 		}
17 17
 
18
-		if( isset( $this->args['desc'] )) {
19
-			unset( $this->args['desc'] );
18
+		if (isset($this->args['desc'])) {
19
+			unset($this->args['desc']);
20 20
 		}
21 21
 
22
-		if( isset( $this->args['id'] )) {
23
-			unset( $this->args['id'] );
22
+		if (isset($this->args['id'])) {
23
+			unset($this->args['id']);
24 24
 		}
25 25
 
26 26
 		return parent::render([
Please login to merge, or discard this patch.
src/Forms/Fields/Textarea.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,16 +11,16 @@
 block discarded – undo
11 11
 	/**
12 12
 	 * @return string
13 13
 	 */
14
-	public function render( array $defaults = [] )
14
+	public function render(array $defaults = [])
15 15
 	{
16
-		$defaults = wp_parse_args( $defaults, [
16
+		$defaults = wp_parse_args($defaults, [
17 17
 			'class' => 'large-text',
18 18
 			'rows'  => 3,
19 19
 			'type'  => 'textarea',
20 20
 		]);
21 21
 
22
-		return sprintf( '<textarea %s>%s</textarea>%s',
23
-			$this->implodeAttributes( $defaults ),
22
+		return sprintf('<textarea %s>%s</textarea>%s',
23
+			$this->implodeAttributes($defaults),
24 24
 			$this->args['value'],
25 25
 			$this->generateDescription()
26 26
 		);
Please login to merge, or discard this patch.
src/Forms/Fields/Base.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	protected $element;
40 40
 
41
-	public function __construct( array $args = [] )
41
+	public function __construct(array $args = [])
42 42
 	{
43 43
 		$this->args = $args;
44 44
 	}
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	 * @return mixed
50 50
 	 * @throws Exception
51 51
 	 */
52
-	public function __get( $property )
52
+	public function __get($property)
53 53
 	{
54
-		switch( $property ) {
54
+		switch ($property) {
55 55
 			case 'args';
56 56
 			case 'dependencies';
57 57
 			case 'element';
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 			return $this->$property;
61 61
 		}
62 62
 
63
-		throw new Exception( 'Invalid ' . __CLASS__ . ' property: ' . $property );
63
+		throw new Exception('Invalid ' . __CLASS__ . ' property: ' . $property);
64 64
 	}
65 65
 
66 66
 	/**
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
 	 *
71 71
 	 * @return null|string
72 72
 	 */
73
-	public function generateDescription( $paragraph = true )
73
+	public function generateDescription($paragraph = true)
74 74
 	{
75
-		if( !isset( $this->args['desc'] ) || !$this->args['desc'] )return;
75
+		if (!isset($this->args['desc']) || !$this->args['desc'])return;
76 76
 
77
-		$tag = ( !!$paragraph || $paragraph == 'p' ) ? 'p' : 'span';
77
+		$tag = (!!$paragraph || $paragraph == 'p') ? 'p' : 'span';
78 78
 
79
-		return sprintf( '<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc'] );
79
+		return sprintf('<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc']);
80 80
 	}
81 81
 
82 82
 	/**
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	public function generateLabel()
88 88
 	{
89
-		if( empty( $this->args['label'] ))return;
89
+		if (empty($this->args['label']))return;
90 90
 
91 91
 		$for = !!$this->args['id']
92 92
 			? " for=\"{$this->args['id']}\""
93 93
 			: '';
94 94
 
95
-		return sprintf( '<label%s>%s</label>', $for, $this->args['label'] );
95
+		return sprintf('<label%s>%s</label>', $for, $this->args['label']);
96 96
 	}
97 97
 
98 98
 	/**
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @return string
111 111
 	 */
112
-	protected function camelCase( $value )
112
+	protected function camelCase($value)
113 113
 	{
114
-		$value = ucwords( str_replace( ['-', '_'], ' ', $value ));
114
+		$value = ucwords(str_replace(['-', '_'], ' ', $value));
115 115
 
116
-		return lcfirst( str_replace( ' ', '', $value ));
116
+		return lcfirst(str_replace(' ', '', $value));
117 117
 	}
118 118
 
119 119
 	/**
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @return array
123 123
 	 */
124
-	protected function implodeAttributes( $defaults = [] )
124
+	protected function implodeAttributes($defaults = [])
125 125
 	{
126
-		return $this->normalize( $defaults, 'implode' );
126
+		return $this->normalize($defaults, 'implode');
127 127
 	}
128 128
 
129 129
 	/**
@@ -131,24 +131,24 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @return null|string
133 133
 	 */
134
-	protected function implodeOptions( $method = 'select_option', $default = null )
134
+	protected function implodeOptions($method = 'select_option', $default = null)
135 135
 	{
136 136
 		$this->args['default'] ?: $this->args['default'] = $default;
137 137
 
138
-		$method = $this->camelCase( $method );
138
+		$method = $this->camelCase($method);
139 139
 
140
-		$method = method_exists( $this, $method )
140
+		$method = method_exists($this, $method)
141 141
 			? $method
142 142
 			: 'selectOption';
143 143
 
144 144
 		$i = 0;
145 145
 
146
-		if( $method === 'singleInput' ) {
146
+		if ($method === 'singleInput') {
147 147
 
148
-			if( !isset( $this->args['options'] ) || empty( $this->args['options'] ))return;
148
+			if (!isset($this->args['options']) || empty($this->args['options']))return;
149 149
 
150 150
 			// hack to make sure unset single checkbox values start at 1 instead of 0
151
-			if( key( $this->args['options'] ) === 0 ) {
151
+			if (key($this->args['options']) === 0) {
152 152
 				$options = ['1' => $this->args['options'][0]];
153 153
 				$this->args['options'] = $options;
154 154
 			}
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 			return $this->singleInput();
157 157
 		}
158 158
 
159
-		return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use ( &$i, $method ) {
160
-			return $carry .= $this->$method( $key, $i++ );
159
+		return array_reduce(array_keys($this->args['options']), function($carry, $key) use (&$i, $method) {
160
+			return $carry .= $this->$method($key, $i++);
161 161
 		});
162 162
 	}
163 163
 
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
 	 *
169 169
 	 * @return array
170 170
 	 */
171
-	protected function normalize( array $defaults = [], $implode = false )
171
+	protected function normalize(array $defaults = [], $implode = false)
172 172
 	{
173
-		$args = $this->mergeAttributesWith( $defaults );
173
+		$args = $this->mergeAttributesWith($defaults);
174 174
 
175 175
 		$normalize = new Normalize;
176 176
 
177
-		return ( $this->element && method_exists( $normalize, $this->element ))
178
-			? $normalize->{$this->element}( $args, $implode )
179
-			: ( !!$implode ? '' : [] );
177
+		return ($this->element && method_exists($normalize, $this->element))
178
+			? $normalize->{$this->element}($args, $implode)
179
+			: (!!$implode ? '' : []);
180 180
 	}
181 181
 
182 182
 	/**
@@ -184,18 +184,18 @@  discard block
 block discarded – undo
184 184
 	 *
185 185
 	 * @return array
186 186
 	 */
187
-	protected function mergeAttributesWith( array $defaults )
187
+	protected function mergeAttributesWith(array $defaults)
188 188
 	{
189 189
 		// similar to array_merge except overwrite empty values
190
-		foreach( $defaults as $key => $value ) {
191
-			if( isset( $this->args[ $key ] ) && !empty( $this->args[ $key ] ))continue;
192
-			$this->args[ $key ] = $value;
190
+		foreach ($defaults as $key => $value) {
191
+			if (isset($this->args[$key]) && !empty($this->args[$key]))continue;
192
+			$this->args[$key] = $value;
193 193
 		}
194 194
 
195 195
 		$attributes = $this->args['attributes'];
196 196
 
197 197
 		// prioritize $attributes over $this->args, don't worry about duplicates
198
-		return array_merge( $this->args, $attributes );
198
+		return array_merge($this->args, $attributes);
199 199
 	}
200 200
 
201 201
 	/**
@@ -207,22 +207,22 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 * @return null|string
209 209
 	 */
210
-	protected function multiInput( $optionKey, $number, $type = 'radio' )
210
+	protected function multiInput($optionKey, $number, $type = 'radio')
211 211
 	{
212
-		$args = $this->multiInputArgs( $type, $optionKey, $number );
212
+		$args = $this->multiInputArgs($type, $optionKey, $number);
213 213
 
214
-		if( !$args )return;
214
+		if (!$args)return;
215 215
 
216 216
 		$attributes = '';
217 217
 
218
-		foreach( $args['attributes'] as $key => $val ) {
219
-			$attributes .= sprintf( '%s="%s" ', $key, $val );
218
+		foreach ($args['attributes'] as $key => $val) {
219
+			$attributes .= sprintf('%s="%s" ', $key, $val);
220 220
 		}
221 221
 
222
-		return sprintf( '<li><label for="%s"><input %s%s/> %s</label></li>',
222
+		return sprintf('<li><label for="%s"><input %s%s/> %s</label></li>',
223 223
 			$args['attributes']['id'],
224 224
 			$attributes,
225
-			checked( $args['value'], $args['attributes']['value'], false ),
225
+			checked($args['value'], $args['attributes']['value'], false),
226 226
 			$args['label']
227 227
 		);
228 228
 	}
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 	 *
237 237
 	 * @return array|null
238 238
 	 */
239
-	protected function multiInputArgs( $type, $optionName, $number )
239
+	protected function multiInputArgs($type, $optionName, $number)
240 240
 	{
241 241
 		$defaults = [
242 242
 			'class' => '',
@@ -247,39 +247,39 @@  discard block
 block discarded – undo
247 247
 
248 248
 		$args = [];
249 249
 
250
-		$value = $this->args['options'][ $optionName ];
250
+		$value = $this->args['options'][$optionName];
251 251
 
252
-		if( is_array( $value )) {
252
+		if (is_array($value)) {
253 253
 			$args = $value;
254 254
 		}
255 255
 
256
-		if( is_string( $value )) {
256
+		if (is_string($value)) {
257 257
 			$label = $value;
258 258
 		}
259 259
 
260
-		isset( $args['name'] ) ?: $args['name'] = $optionName;
261
-		isset( $args['value'] ) ?: $args['value'] = $optionName;
260
+		isset($args['name']) ?: $args['name'] = $optionName;
261
+		isset($args['value']) ?: $args['value'] = $optionName;
262 262
 
263
-		$args = wp_parse_args( $args, $defaults );
263
+		$args = wp_parse_args($args, $defaults);
264 264
 
265
-		if( !isset( $label ) || $args['name'] === '' )return;
265
+		if (!isset($label) || $args['name'] === '')return;
266 266
 
267 267
 		$args['id']   = $this->args['id'] . "-{$number}";
268
-		$args['name'] = $this->args['name'] . ( $type === 'checkbox' && $this->multi ? '[]' : '' );
268
+		$args['name'] = $this->args['name'] . ($type === 'checkbox' && $this->multi ? '[]' : '');
269 269
 
270
-		$args = array_filter( $args, function( $value ) {
270
+		$args = array_filter($args, function($value) {
271 271
 			return $value !== '';
272 272
 		});
273 273
 
274
-		if( is_array( $this->args['value'] )) {
275
-			if( in_array( $args['value'], $this->args['value'] )) {
274
+		if (is_array($this->args['value'])) {
275
+			if (in_array($args['value'], $this->args['value'])) {
276 276
 				$this->args['default'] = $args['value'];
277 277
 			}
278 278
 		}
279
-		else if( $this->args['value'] ) {
279
+		else if ($this->args['value']) {
280 280
 			$this->args['default'] = $this->args['value'];
281 281
 		}
282
-		else if( $type == 'radio' && !$this->args['default'] ) {
282
+		else if ($type == 'radio' && !$this->args['default']) {
283 283
 			$this->args['default'] = 0;
284 284
 		}
285 285
 
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
 	 *
299 299
 	 * @return null|string
300 300
 	 */
301
-	protected function multiInputCheckbox( $optionKey, $number )
301
+	protected function multiInputCheckbox($optionKey, $number)
302 302
 	{
303
-		return $this->multiInput( $optionKey, $number, 'checkbox' );
303
+		return $this->multiInput($optionKey, $number, 'checkbox');
304 304
 	}
305 305
 
306 306
 	/**
@@ -310,12 +310,12 @@  discard block
 block discarded – undo
310 310
 	 *
311 311
 	 * @return string
312 312
 	 */
313
-	protected function selectOption( $optionKey )
313
+	protected function selectOption($optionKey)
314 314
 	{
315
-		return sprintf( '<option value="%s"%s>%s</option>',
315
+		return sprintf('<option value="%s"%s>%s</option>',
316 316
 			$optionKey,
317
-			selected( $this->args['value'], $optionKey, false ),
318
-			$this->args['options'][ $optionKey ]
317
+			selected($this->args['value'], $optionKey, false),
318
+			$this->args['options'][$optionKey]
319 319
 		);
320 320
 	}
321 321
 
@@ -326,27 +326,27 @@  discard block
 block discarded – undo
326 326
 	 *
327 327
 	 * @return null|string
328 328
 	 */
329
-	protected function singleInput( $type = 'checkbox' )
329
+	protected function singleInput($type = 'checkbox')
330 330
 	{
331
-		$optionKey = key( $this->args['options'] );
331
+		$optionKey = key($this->args['options']);
332 332
 
333
-		$args = $this->multiInputArgs( $type, $optionKey, 1 );
333
+		$args = $this->multiInputArgs($type, $optionKey, 1);
334 334
 
335
-		if( !$args )return;
335
+		if (!$args)return;
336 336
 
337 337
 		$atts = $this->normalize();
338
-		$atts = wp_parse_args( $args['attributes'], $atts );
338
+		$atts = wp_parse_args($args['attributes'], $atts);
339 339
 
340 340
 		$attributes = '';
341 341
 
342
-		foreach( $atts as $key => $val ) {
343
-			$attributes .= sprintf( '%s="%s" ', $key, $val );
342
+		foreach ($atts as $key => $val) {
343
+			$attributes .= sprintf('%s="%s" ', $key, $val);
344 344
 		}
345 345
 
346
-		return sprintf( '<label for="%s"><input %s%s/> %s</label>',
346
+		return sprintf('<label for="%s"><input %s%s/> %s</label>',
347 347
 			$atts['id'],
348 348
 			$attributes,
349
-			checked( $args['value'], $atts['value'], false ),
349
+			checked($args['value'], $atts['value'], false),
350 350
 			$args['label']
351 351
 		);
352 352
 	}
Please login to merge, or discard this patch.