CategoryForm   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 317
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 11
dl 0
loc 317
ccs 148
cts 148
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C render() 0 304 12
1
<?php
2
namespace Redaxscript\Admin\View;
3
4
use Redaxscript\Admin;
5
use Redaxscript\Dater;
6
use Redaxscript\Html;
7
use Redaxscript\Module;
8
use Redaxscript\Validator;
9
use function count;
10
use function json_decode;
11
12
/**
13
 * children class to create the category form
14
 *
15
 * @since 3.0.0
16
 *
17
 * @package Redaxscript
18
 * @category View
19
 * @author Henry Ruhs
20
 */
21
22
class CategoryForm extends ViewAbstract
23
{
24
	/**
25
	 * render the view
26
	 *
27
	 * @since 3.0.0
28
	 *
29
	 * @param int $categoryId identifier of the category
30
	 *
31
	 * @return string
32
	 */
33 4
34
	public function render(int $categoryId = null) : string
35 4
	{
36 4
		$output = Module\Hook::trigger('adminCategoryFormStart');
37 4
		$helperOption = new Helper\Option($this->_language);
38 4
		$categoryModel = new Admin\Model\Category();
39 4
		$category = $categoryModel->getById($categoryId);
40 4
		$aliasValidator = new Validator\Alias();
41
		$dater = new Dater();
42
		$dater->init($category->date);
43
44 4
		/* html element */
45
46 4
		$titleElement = new Html\Element();
47
		$titleElement
48 4
			->init('h2',
49
			[
50 4
				'class' => 'rs-admin-title-content',
51 4
			])
52 4
			->text($category->title ? : $this->_language->get('category_new'));
53
		$formElement = new Admin\Html\Form($this->_registry, $this->_language);
54 4
		$formElement->init(
55
		[
56
			'form' =>
57
			[
58
				'class' => 'rs-admin-js-validate rs-admin-js-alias rs-admin-fn-tab rs-admin-component-tab rs-admin-form-default'
59
			],
60
			'button' =>
61
			[
62
				'create' =>
63
				[
64
					'name' => self::class
65
				],
66
				'save' =>
67
				[
68
					'name' => self::class
69
				]
70
			],
71
			'link' =>
72
			[
73 4
				'cancel' =>
74
				[
75
					'href' => $this->_registry->get('categoriesEdit') && $this->_registry->get('categoriesDelete') ? $this->_registry->get('parameterRoute') . 'admin/view/categories' : $this->_registry->get('parameterRoute') . 'admin'
76
				],
77 4
				'delete' =>
78
				[
79
					'href' => $category->id ? $this->_registry->get('parameterRoute') . 'admin/delete/categories/' . $category->id . '/' . $this->_registry->get('token') : null
80
				]
81
			]
82
		]);
83
84
		/* create the form */
85
86
		$formElement
87
88 4
			/* category */
89
90 4
			->radio(
91
			[
92
				'id' => self::class . '\Category',
93
				'class' => 'rs-admin-fn-status-tab',
94
				'name' => self::class . '\Tab',
95 4
				'checked' => 'checked'
96
			])
97 4
			->label($this->_language->get('category'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('category') 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...
98
			[
99
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
100 4
				'for' => self::class . '\Category'
101 4
			])
102
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
103 4
			->label($this->_language->get('title'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('title') 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...
104
			[
105 4
				'for' => 'title'
106
			])
107 4
			->text(
108 4
			[
109 4
				'autofocus' => 'autofocus',
110 4
				'class' => 'rs-admin-js-alias-input rs-admin-field-default rs-admin-field-text',
111 4
				'id' => 'title',
112 4
				'name' => 'title',
113
				'required' => 'required',
114 4
				'value' => $category->title
115 4
			])
116
			->append('</li><li>')
117 4
			->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...
118
			[
119 4
				'for' => 'alias'
120
			])
121 4
			->text(
122 4
			[
123 4
				'class' => 'rs-admin-js-alias-output rs-admin-field-default rs-admin-field-text',
124 4
				'id' => 'alias',
125 4
				'name' => 'alias',
126 4
				'pattern' => $aliasValidator->getFormPattern(),
127
				'required' => 'required',
128 4
				'value' => $category->alias
129 4
			])
130
			->append('</li><li>')
131 4
			->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...
132
			[
133 4
				'for' => 'description'
134
			])
135 4
			->textarea(
136 4
			[
137 4
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
138 4
				'id' => 'description',
139 4
				'name' => 'description',
140
				'rows' => 1,
141 4
				'value' => $category->description
142 4
			])
143
			->append('</li><li>')
144 4
			->label($this->_language->get('keywords'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('keywords') 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...
145
			[
146 4
				'for' => 'keywords'
147
			])
148 4
			->textarea(
149 4
			[
150 4
				'class' => 'rs-admin-js-resize rs-admin-field-textarea rs-admin-field-small',
151 4
				'id' => 'keywords',
152 4
				'name' => 'keywords',
153
				'rows' => 1,
154 4
				'value' => $category->keywords
155 4
			])
156
			->append('</li><li>')
157 4
			->label($this->_language->get('robots'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('robots') 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...
158
			[
159 4
				'for' => 'robots'
160
			])
161 4
			->select($helperOption->getRobotArray(),
162
			[
163
				$category->robots
164 4
			],
165
			[
166
				'id' => 'robots',
167 4
				'name' => 'robots'
168
			])
169
			->append('</li></ul>')
170
171 4
			/* general */
172
173 4
			->radio(
174
			[
175
				'id' => self::class . '\General',
176
				'class' => 'rs-admin-fn-status-tab',
177 4
				'name' => self::class . '\Tab'
178
			])
179 4
			->label($this->_language->get('general'),
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_language->get('general') 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
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
182 4
				'for' => self::class . '\General'
183 4
			])
184
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
185 4
			->label($this->_language->get('language'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('language') 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...
186
			[
187 4
				'for' => 'language'
188
			])
189 4
			->select($helperOption->getLanguageArray(),
190
			[
191
				$category->language
192 4
			],
193
			[
194
				'id' => 'language',
195 4
				'name' => 'language'
196 4
			])
197
			->append('</li><li>')
198 4
			->label($this->_language->get('template'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('template') 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...
199
			[
200 4
				'for' => 'template'
201
			])
202 4
			->select($helperOption->getTemplateArray(),
203
			[
204
				$category->template
205 4
			],
206
			[
207
				'id' => 'template',
208 4
				'name' => 'template'
209 4
			])
210
			->append('</li><li>')
211 4
			->label($this->_language->get('category_sibling'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('category_sibling') 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...
212
			[
213 4
				'for' => 'sibling'
214
			])
215 4
			->select($helperOption->getSiblingForCategoryArray($category->id),
216
			[
217
				$category->sibling
218 4
			],
219
			[
220
				'id' => 'sibling',
221 4
				'name' => 'sibling'
222 4
			])
223
			->append('</li><li>')
224 4
			->label($this->_language->get('category_parent'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('category_parent') 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...
225
			[
226 4
				'for' => 'parent'
227
			])
228 4
			->select($helperOption->getParentForCategoryArray($category->id),
229
			[
230
				$category->parent
231 4
			],
232
			[
233
				'id' => 'parent',
234 4
				'name' => 'parent'
235
			])
236
			->append('</li></ul>')
237
238 4
			/* customize */
239
240 4
			->radio(
241
			[
242
				'id' => self::class . '\Customize',
243
				'class' => 'rs-admin-fn-status-tab',
244 4
				'name' => self::class . '\Tab'
245
			])
246 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...
247
			[
248
				'class' => 'rs-admin-fn-toggle-tab rs-admin-label-tab',
249 4
				'for' => self::class . '\Customize'
250 4
			])
251
			->append('<ul class="rs-admin-fn-content-tab rs-admin-box-tab"><li>')
252 4
			->label($this->_language->get('status'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
253
			[
254 4
				'for' => 'status'
255
			])
256 4
			->select($helperOption->getVisibleArray(),
257
			[
258
				$category->id ? $category->status : 1
259 4
			],
260
			[
261
				'id' => 'status',
262 4
				'name' => 'status'
263 4
			])
264
			->append('</li><li>')
265 4
			->label($this->_language->get('rank'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('rank') 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...
266
			[
267 4
				'for' => 'rank'
268
			])
269 4
			->number(
270 4
			[
271 4
				'id' => 'rank',
272
				'name' => 'rank',
273 4
				'value' => $category->id ? $category->rank : $categoryModel->query()->max('rank') + 1
274 4
			])
275
			->append('</li>');
276
		if ($this->_registry->get('groupsEdit'))
277 4
		{
278 4
			$formElement
279
				->append('<li>')
280 4
				->label($this->_language->get('access'),
0 ignored issues
show
Bug introduced by redaxmedia
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...
281
				[
282 4
					'for' => 'access'
283 4
				])
284
				->select($helperOption->getGroupArray(),
285 4
				(array)json_decode($category->access),
286 4
				[
287 4
					'id' => 'access',
288 4
					'name' => 'access[]',
289
					'multiple' => 'multiple',
290 4
					'size' => count($helperOption->getGroupArray())
291
				])
292
				->append('</li>');
293 4
		}
294 4
		$formElement
295
			->append('<li>')
296 4
			->label($this->_language->get('date'),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('date') 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...
297
			[
298 4
				'for' => 'date'
299
			])
300 4
			->datetime(
301 4
			[
302 4
				'id' => 'date',
303
				'name' => 'date',
304 4
				'value' => $dater->formatField()
305 4
			])
306
			->append('</li></ul>')
307 4
			->hidden(
308 4
			[
309
				'name' => 'id',
310 4
				'value' => $category->id
311 4
			])
312 4
			->token()
313 4
			->append('<div class="rs-admin-wrapper-button">')
314
			->cancel();
315 2
		if ($category->id)
316
		{
317 1
			if ($this->_registry->get('categoriesDelete'))
318
			{
319 2
				$formElement->delete();
320
			}
321 2
			if ($this->_registry->get('categoriesEdit'))
322
			{
323
				$formElement->save();
324 2
			}
325
		}
326 1
		else if ($this->_registry->get('categoriesNew'))
327
		{
328 4
			$formElement->create();
329
		}
330
		$formElement->append('</div>');
331
332 4
		/* collect output */
333 4
334 4
		$output .= $titleElement . $formElement;
335
		$output .= Module\Hook::trigger('adminCategoryFormEnd');
336
		return $output;
337
	}
338
}
339