GroupForm   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 324
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 10
dl 0
loc 324
ccs 160
cts 160
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D render() 0 311 15
1
<?php
2
namespace Redaxscript\Admin\View;
3
4
use Redaxscript\Admin;
5
use Redaxscript\Html;
6
use Redaxscript\Module;
7
use Redaxscript\Validator;
8
use function count;
9
use function json_decode;
10
11
/**
12
 * children class to create the group form
13
 *
14
 * @since 3.0.0
15
 *
16
 * @package Redaxscript
17
 * @category View
18
 * @author Henry Ruhs
19
 */
20
21
class GroupForm extends ViewAbstract
22
{
23
	/**
24
	 * render the view
25
	 *
26
	 * @since 3.0.0
27
	 *
28
	 * @param int $groupId identifier of the group
29
	 *
30
	 * @return string
31
	 */
32 6
33
	public function render(int $groupId = null) : string
34 6
	{
35 6
		$output = Module\Hook::trigger('adminGroupFormStart');
36 6
		$groupModel = new Admin\Model\Group();
37 6
		$group = $groupModel->getById($groupId);
38
		$aliasValidator = new Validator\Alias();
39
		$helperOption = new Helper\Option($this->_language);
40
41 6
		/* html element */
42
43 6
		$titleElement = new Html\Element();
44
		$titleElement
45 6
			->init('h2',
46
			[
47 6
				'class' => 'rs-admin-title-content',
48 6
			])
49 6
			->text($group->name ? : $this->_language->get('group_new'));
50
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
51 6
		$formElement->init(
52
		[
53
			'form' =>
54
			[
55
				'class' => 'rs-admin-js-validate rs-admin-js-alias rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default'
56
			],
57
			'button' =>
58
			[
59
				'create' =>
60
				[
61
					'name' => self::class
62
				],
63
				'save' =>
64
				[
65
					'name' => self::class
66
				]
67
			],
68
			'link' =>
69
			[
70 6
				'cancel' =>
71
				[
72
					'href' => $this->_registry->get('groupsEdit') && $this->_registry->get('groupsDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/groups' : $this->_registry->get('parameterRoute') . 'admin'
73
				],
74 6
				'delete' =>
75
				[
76
					'href' => $group->id ? $this->_registry->get('parameterRoute') . 'admin/delete/groups/' . $group->id . '/' . $this->_registry->get('token') : null
77
				]
78
			]
79
		]);
80
81
		/* create the form */
82
83
		$formElement
84
85 6
			/* group */
86
87 6
			->radio(
88
			[
89
				'id' => self::class . '\Group',
90
				'class' => 'rs-admin-fn-status-tab',
91
				'name' => self::class . '\Tab',
92 6
				'checked' => 'checked'
93
			])
94 6
			->label($this->_language->get('group'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('group') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
95
			[
96
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
97 6
				'for' => self::class . '\Group'
98 6
			])
99
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
100 6
			->label($this->_language->get('name'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('name') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
101
			[
102 6
				'for' => 'name'
103
			])
104 6
			->text(
105 6
			[
106 6
				'autofocus' => 'autofocus',
107 6
				'class' => 'rs-admin-js-alias-input rs-admin-field-default rs-admin-field-text',
108 6
				'id' => 'name',
109 6
				'name' => 'name',
110
				'required' => 'required',
111 6
				'value' => $group->name
112 6
			])
113
			->append('</li>');
114
		if (!$group->id)
115 2
		{
116 2
			$formElement
117
				->append('<li>')
118 2
				->label($this->_language->get('alias'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('alias') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
119
				[
120 2
					'for' => 'alias'
121
				])
122 2
				->text(
123 2
				[
124 2
					'class' => 'rs-admin-js-alias-output rs-admin-field-default rs-admin-field-text',
125 2
					'id' => 'alias',
126 2
					'name' => 'alias',
127 2
					'pattern' => $aliasValidator->getFormPattern(),
128
					'required' => 'required',
129 2
					'value' => $group->alias
130
				])
131
				->append('</li>');
132 6
		}
133 6
		$formElement
134
			->append('<li>')
135 6
			->label($this->_language->get('description'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('description') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
136
			[
137 6
				'for' => 'description'
138
			])
139 6
			->textarea(
140 6
			[
141 6
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
142 6
				'id' => 'description',
143 6
				'name' => 'description',
144
				'rows' => 1,
145 6
				'value' => $group->description
146 6
			])
147
			->append('</li></ul>');
148
		if (!$group->id || $group->id > 1)
149
		{
150
			$formElement
151
152 4
				/* access */
153
154 4
				->radio(
155
				[
156
					'id' => self::class . '\Access',
157
					'class' => 'rs-admin-fn-status-tab',
158 4
					'name' => self::class . '\Tab'
159
				])
160 4
				->label($this->_language->get('access'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('access') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
161
				[
162
					'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
163 4
					'for' => self::class . '\Access'
164 4
				])
165
				->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
166 4
				->label($this->_language->get('categories'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('categories') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
167
				[
168 4
					'for' => 'categories'
169 4
				])
170
				->select($helperOption->getPermissionArray(),
171 4
				(array)json_decode($group->categories),
172 4
				[
173 4
					'id' => 'categories',
174 4
					'name' => 'categories[]',
175
					'multiple' => 'multiple',
176 4
					'size' => count($helperOption->getPermissionArray())
177 4
				])
178
				->append('</li><li>')
179 4
				->label($this->_language->get('articles'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('articles') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
180
				[
181 4
					'for' => 'articles'
182 4
				])
183
				->select($helperOption->getPermissionArray(),
184 4
				(array)json_decode($group->articles),
185 4
				[
186 4
					'id' => 'articles',
187 4
					'name' => 'articles[]',
188
					'multiple' => 'multiple',
189 4
					'size' => count($helperOption->getPermissionArray())
190 4
				])
191
				->append('</li><li>')
192 4
				->label($this->_language->get('extras'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('extras') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
193
				[
194 4
					'for' => 'extras'
195 4
				])
196
				->select($helperOption->getPermissionArray(),
197 4
				(array)json_decode($group->extras),
198 4
				[
199 4
					'id' => 'extras',
200 4
					'name' => 'extras[]',
201
					'multiple' => 'multiple',
202 4
					'size' => count($helperOption->getPermissionArray())
203 4
				])
204
				->append('</li><li>')
205 4
				->label($this->_language->get('comments'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('comments') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
206
				[
207 4
					'for' => 'comments'
208 4
				])
209
				->select($helperOption->getPermissionArray(),
210 4
				(array)json_decode($group->comments),
211 4
				[
212 4
					'id' => 'comments',
213 4
					'name' => 'comments[]',
214
					'multiple' => 'multiple',
215 4
					'size' => count($helperOption->getPermissionArray())
216 4
				])
217
				->append('</li><li>')
218 4
				->label($this->_language->get('groups'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('groups') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
219
				[
220 4
					'for' => 'groups'
221 4
				])
222
				->select($helperOption->getPermissionArray(),
223 4
				(array)json_decode($group->groups),
224 4
				[
225 4
					'id' => 'groups',
226 4
					'name' => 'groups[]',
227
					'multiple' => 'multiple',
228 4
					'size' => count($helperOption->getPermissionArray())
229 4
				])
230
				->append('</li><li>')
231 4
				->label($this->_language->get('users'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('users') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
232
				[
233 4
					'for' => 'users'
234 4
				])
235
				->select($helperOption->getPermissionArray(),
236 4
				(array)json_decode($group->users),
237 4
				[
238 4
					'id' => 'users',
239 4
					'name' => 'users[]',
240
					'multiple' => 'multiple',
241 4
					'size' => count($helperOption->getPermissionArray())
242 4
				])
243
				->append('</li><li>')
244 4
				->label($this->_language->get('modules'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('modules') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
245
				[
246 4
					'for' => 'modules'
247 4
				])
248
				->select($helperOption->getPermissionArray('modules'),
249 4
				(array)json_decode($group->modules),
250 4
				[
251 4
					'id' => 'modules',
252 4
					'name' => 'modules[]',
253
					'multiple' => 'multiple',
254 4
					'size' => count($helperOption->getPermissionArray('modules'))
255 4
				])
256
				->append('</li><li>')
257 4
				->label($this->_language->get('settings'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('settings') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
258
				[
259 4
					'for' => 'settings'
260
				])
261 4
				->select($helperOption->getPermissionArray('settings'),
262
				[
263
					$group->settings
264 4
				],
265
				[
266
					'id' => 'settings',
267 4
					'name' => 'settings'
268
				])
269
				->append('</li></ul>')
270
271 4
				/* customize */
272
273 4
				->radio(
274
				[
275
					'id' => self::class . '\Customize',
276
					'class' => 'rs-admin-fn-status-tab',
277 4
					'name' => self::class . '\Tab'
278
				])
279 4
				->label($this->_language->get('customize'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('customize') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
280
				[
281
					'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
282 4
					'for' => self::class . '\Customize'
283 4
				])
284
				->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
285 4
				->label($this->_language->get('filter'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('filter') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
286
				[
287 4
					'for' => 'filter'
288
				])
289 4
				->select($helperOption->getToggleArray(),
290
				[
291
					$group->id ? $group->filter : 1
292 4
				],
293
				[
294
					'id' => 'filter',
295 4
					'name' => 'filter'
296 4
				])
297
				->append('</li><li>')
298 4
				->label($this->_language->get('status'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('status') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\Html\Form::label() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
299
				[
300 4
					'for' => 'status'
301
				])
302 4
				->select($helperOption->getToggleArray(),
303
				[
304
					$group->id ? $group->status : 1
305 4
				],
306
				[
307
					'id' => 'status',
308 4
					'name' => 'status'
309
				])
310
				->append('</li></ul>');
311 6
		}
312
		$formElement
313 6
			->hidden(
314 6
			[
315
				'name' => 'id',
316 6
				'value' => $group->id
317 6
			])
318 6
			->token()
319 6
			->append('<div class="rs-admin-wrapper-button">')
320
			->cancel();
321 4
		if ($group->id)
322
		{
323 1
			if ($this->_registry->get('groupsDelete') && $group->id > 1)
324
			{
325 4
				$formElement->delete();
326
			}
327 4
			if ($this->_registry->get('groupsEdit'))
328
			{
329
				$formElement->save();
330 2
			}
331
		}
332 1
		else if ($this->_registry->get('groupsNew'))
333
		{
334 6
			$formElement->create();
335
		}
336
		$formElement->append('</div>');
337
338 6
		/* collect output */
339 6
340 6
		$output .= $titleElement . $formElement;
341
		$output .= Module\Hook::trigger('adminGroupFormEnd');
342
		return $output;
343
	}
344
}
345