Router   F
last analyzed

Complexity

Total Complexity 88

Size/Duplication

Total Lines 547
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 32

Test Coverage

Coverage 45.36%

Importance

Changes 0
Metric Value
wmc 88
lcom 1
cbo 32
dl 0
loc 547
ccs 83
cts 183
cp 0.4536
rs 2
c 0
b 0
f 0

20 Methods

Rating   Name   Duplication   Size   Complexity  
A routeHeader() 0 20 5
D routeContent() 0 92 21
A _tokenGuard() 0 16 4
F _authGuard() 0 23 12
A _updateLast() 0 8 2
A _processCategory() 0 5 1
A _processArticle() 0 5 1
A _processExtra() 0 5 1
A _processComment() 0 5 1
A _processUser() 0 5 1
A _processGroup() 0 5 1
A _processModule() 0 5 1
A _processSetting() 0 5 1
A _processCommon() 0 20 2
B _renderView() 0 43 8
B _renderNew() 0 38 7
C _renderEdit() 0 49 16
A _messengerFactory() 0 4 1
A _errorToken() 0 7 1
A _errorAccess() 0 7 1

How to fix   Complexity   

Complex Class

Complex classes like Router often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Router, and based on these observations, apply Extract Interface, too.

1
<?php
2
namespace Redaxscript\Admin\Router;
3
4
use Redaxscript\Admin;
5
use Redaxscript\Header;
6
use Redaxscript\Module;
7
use Redaxscript\Router\RouterAbstract;
8
use function in_array;
9
10
/**
11
 * parent class to provide the admin router
12
 *
13
 * @since 3.3.0
14
 *
15
 * @package Redaxscript
16
 * @category Router
17
 * @author Henry Ruhs
18
 */
19
20
class Router extends RouterAbstract
21
{
22
	/**
23
	 * route the header
24
	 *
25
	 * @since 3.3.0
26
	 *
27
	 * @return bool
28
	 */
29
30 2
	public function routeHeader() : bool
31
	{
32 2
		Module\Hook::trigger('adminRouteHeader');
33 2
		$adminParameter = $this->getAdmin();
34
35
		/* handle break */
36
37 2
		if ($this->_registry->get('adminRouterBreak'))
38
		{
39 1
			Header::responseCode(202);
40
		}
41
42
		/* handle guard */
43
44 2
		if ($adminParameter && ($this->_tokenGuard() || $this->_authGuard()))
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $adminParameter of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
45
		{
46
			Header::responseCode(403);
47
		}
48 2
		return (bool)$this->_registry->get('adminRouterBreak');
49
	}
50
51
	/**
52
	 * route the content
53
	 *
54
	 * @since 3.3.0
55
	 *
56
	 * @return string|null
57
	 */
58
59 10
	public function routeContent() : ?string
60
	{
61 10
		Module\Hook::trigger('adminRouteContent');
62 10
		$firstParameter = $this->getFirst();
63 10
		$adminParameter = $this->getAdmin();
64 10
		$tableParameter = $this->getTable();
65
66
		/* handle admin */
67
68 10
		if ($firstParameter === 'admin')
69
		{
70
			/* handle break */
71
72 9
			if ($this->_registry->get('adminRouterBreak'))
73
			{
74
				return '<!-- adminRouterBreak -->';
75
			}
76
77
			/* handle guard */
78
79 9
			if ($adminParameter)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $adminParameter of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
80
			{
81 9
				if ($this->_tokenGuard())
82
				{
83 1
					return $this->_errorToken();
84
				}
85 8
				if ($this->_authGuard())
86
				{
87
					return $this->_errorAccess();
88
				}
89
			}
90
91
			/* handle update */
92
93 8
			if (!$adminParameter || $adminParameter === 'view' && $tableParameter === 'users' || $this->_registry->get('cronUpdate'))
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $adminParameter of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
94
			{
95
				$this->_updateLast();
96
			}
97
98
			/* handle post */
99
100 8
			if ($this->_request->getPost('Redaxscript\Admin\View\CategoryForm'))
101
			{
102 1
				return $this->_processCategory();
103
			}
104 7
			if ($this->_request->getPost('Redaxscript\Admin\View\ArticleForm'))
105
			{
106 1
				return $this->_processArticle();
107
			}
108 6
			if ($this->_request->getPost('Redaxscript\Admin\View\ExtraForm'))
109
			{
110 1
				return $this->_processExtra();
111
			}
112 5
			if ($this->_request->getPost('Redaxscript\Admin\View\CommentForm'))
113
			{
114 1
				return $this->_processComment();
115
			}
116 4
			if ($this->_request->getPost('Redaxscript\Admin\View\UserForm'))
117
			{
118 1
				return $this->_processUser();
119
			}
120 3
			if ($this->_request->getPost('Redaxscript\Admin\View\GroupForm'))
121
			{
122 1
				return $this->_processGroup();
123
			}
124 2
			if ($this->_request->getPost('Redaxscript\Admin\View\ModuleForm'))
125
			{
126 1
				return $this->_processModule();
127
			}
128 1
			if ($this->_request->getPost('Redaxscript\Admin\View\SettingForm'))
129
			{
130 1
				return $this->_processSetting();
131
			}
132
133
			/* handle route */
134
135
			if ($adminParameter === 'view')
136
			{
137
				return $this->_renderView();
138
			}
139
			if ($adminParameter === 'new')
140
			{
141
				return $this->_renderNew();
142
			}
143
			if ($adminParameter === 'edit')
144
			{
145
				return $this->_renderEdit();
146
			}
147
			return $this->_processCommon();
148
		}
149 1
		return null;
150
	}
151
152
	/**
153
	 * token guard
154
	 *
155
	 * @since 3.3.0
156
	 *
157
	 * @return bool
158
	 */
159
160 9
	protected function _tokenGuard() : bool
161
	{
162 9
		$adminParameter = $this->getAdmin();
163 9
		$tokenParameter = $this->getToken();
164
		$tokenArray =
165
		[
166 9
			'enable',
167
			'disable',
168
			'publish',
169
			'unpublish',
170
			'install',
171
			'uninstall',
172
			'delete'
173
		];
174 9
		return $this->_request->get('post') && $this->_request->getPost('token') !== $this->_registry->get('token') || in_array($adminParameter, $tokenArray) && !$tokenParameter;
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $tokenParameter of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
175
	}
176
177
	/**
178
	 * auth guard
179
	 *
180
	 * @since 3.3.0
181
	 *
182
	 * @return bool
183
	 */
184
185 8
	protected function _authGuard() : bool
186
	{
187 8
		$adminParameter = $this->getAdmin();
188 8
		$tableParameter = $this->getTable();
189 8
		$idParameter = $this->getId();
190
		$myId = (int)$this->_registry->get('myId');
191
		$editArray =
192 8
		[
193
			'edit',
194
			'view',
195
			'enable',
196
			'disable',
197
			'publish',
198
			'unpublish'
199 8
		];
200 8
		$permissionNew = $adminParameter === 'new' && $this->_registry->get('tableNew');
201 8
		$permissionEdit = in_array($adminParameter, $editArray) && $this->_registry->get('tableEdit');
202 8
		$permissionDelete = $adminParameter === 'delete' && $this->_registry->get('tableDelete');
203 8
		$permissionInstall = $adminParameter === 'install' && $this->_registry->get('tableInstall');
204 8
		$permissionUninstall = $adminParameter === 'uninstall' && $this->_registry->get('tableUninstall');
205 8
		$permissionProfile = $tableParameter === 'users' && $idParameter === $myId;
206
		return !$permissionNew && !$permissionEdit && !$permissionDelete && !$permissionInstall && !$permissionUninstall && !$permissionProfile;
207
	}
208
209
	/**
210
	 * update last
211
	 *
212
	 * @since 4.00
213
	 */
214
215
	protected function _updateLast() : void
216
	{
217
		$userModel = new Admin\Model\User();
218
		if ($this->_registry->get('myId'))
219
		{
220
			$userModel->updateLastById($this->_registry->get('myId'), $this->_registry->get('now'));
0 ignored issues
show
Documentation introduced by redaxmedia
$this->_registry->get('myId') is of type string|array, but the function expects a null|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by redaxmedia
$this->_registry->get('now') is of type string|array, but the function expects a null|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
221
		}
222
	}
223
224
	/**
225
	 * process the category
226
	 *
227
	 * @since 4.00
228
	 *
229
	 * @return string
230
	 */
231 1
232
	protected function _processCategory() : string
233 1
	{
234 1
		$categoryController = new Admin\Controller\Category($this->_registry, $this->_request, $this->_language, $this->_config);
235
		return $categoryController->process($this->_request->getPost('Redaxscript\Admin\View\CategoryForm'));
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_request->getPost...n\\View\\CategoryForm') targeting Redaxscript\Request::getPost() can also be of type array; however, Redaxscript\Admin\Controller\Category::process() 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...
236
	}
237
238
	/**
239
	 * process the article
240
	 *
241
	 * @since 4.00
242
	 *
243
	 * @return string
244
	 */
245 1
246
	protected function _processArticle() : string
247 1
	{
248 1
		$articleController = new Admin\Controller\Article($this->_registry, $this->_request, $this->_language, $this->_config);
249
		return $articleController->process($this->_request->getPost('Redaxscript\Admin\View\ArticleForm'));
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_request->getPost...in\\View\\ArticleForm') targeting Redaxscript\Request::getPost() can also be of type array; however, Redaxscript\Admin\Controller\Article::process() 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...
250
	}
251
252
	/**
253
	 * process the extra
254
	 *
255
	 * @since 4.00
256
	 *
257
	 * @return string
258
	 */
259 1
260
	protected function _processExtra() : string
261 1
	{
262 1
		$extraController = new Admin\Controller\Extra($this->_registry, $this->_request, $this->_language, $this->_config);
263
		return $extraController->process($this->_request->getPost('Redaxscript\Admin\View\ExtraForm'));
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_request->getPost...dmin\\View\\ExtraForm') targeting Redaxscript\Request::getPost() can also be of type array; however, Redaxscript\Admin\Controller\Extra::process() 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...
264
	}
265
266
	/**
267
	 * process the comment
268
	 *
269
	 * @since 4.00
270
	 *
271
	 * @return string
272
	 */
273 1
274
	protected function _processComment() : string
275 1
	{
276 1
		$commentController = new Admin\Controller\Comment($this->_registry, $this->_request, $this->_language, $this->_config);
277
		return $commentController->process($this->_request->getPost('Redaxscript\Admin\View\CommentForm'));
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_request->getPost...in\\View\\CommentForm') targeting Redaxscript\Request::getPost() can also be of type array; however, Redaxscript\Admin\Controller\Comment::process() 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...
278
	}
279
280
	/**
281
	 * process the user
282
	 *
283
	 * @since 4.00
284
	 *
285
	 * @return string
286
	 */
287 1
288
	protected function _processUser() : string
289 1
	{
290 1
		$userController = new Admin\Controller\User($this->_registry, $this->_request, $this->_language, $this->_config);
291
		return $userController->process($this->_request->getPost('Redaxscript\Admin\View\UserForm'));
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_request->getPost...Admin\\View\\UserForm') targeting Redaxscript\Request::getPost() can also be of type array; however, Redaxscript\Admin\Controller\User::process() 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...
292
	}
293
294
	/**
295
	 * process the group
296
	 *
297
	 * @since 4.00
298
	 *
299
	 * @return string
300
	 */
301 1
302
	protected function _processGroup() : string
303 1
	{
304 1
		$groupController = new Admin\Controller\Group($this->_registry, $this->_request, $this->_language, $this->_config);
305
		return $groupController->process($this->_request->getPost('Redaxscript\Admin\View\GroupForm'));
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_request->getPost...dmin\\View\\GroupForm') targeting Redaxscript\Request::getPost() can also be of type array; however, Redaxscript\Admin\Controller\Group::process() 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...
306
	}
307
308
	/**
309
	 * process the module
310
	 *
311
	 * @since 4.00
312
	 *
313
	 * @return string
314
	 */
315 1
316
	protected function _processModule() : string
317 1
	{
318 1
		$moduleController = new Admin\Controller\Module($this->_registry, $this->_request, $this->_language, $this->_config);
319
		return $moduleController->process($this->_request->getPost('Redaxscript\Admin\View\ModuleForm'));
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_request->getPost...min\\View\\ModuleForm') targeting Redaxscript\Request::getPost() can also be of type array; however, Redaxscript\Admin\Controller\Module::process() 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...
320
	}
321
322
	/**
323
	 * process the setting
324
	 *
325
	 * @since 4.00
326
	 *
327
	 * @return string
328
	 */
329 1
330
	protected function _processSetting() : string
331 1
	{
332 1
		$settingController = new Admin\Controller\Setting($this->_registry, $this->_request, $this->_language, $this->_config);
333
		return $settingController->process($this->_request->getPost('Redaxscript\Admin\View\SettingForm'));
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $this->_request->getPost...in\\View\\SettingForm') targeting Redaxscript\Request::getPost() can also be of type array; however, Redaxscript\Admin\Controller\Setting::process() 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...
334
	}
335
336
	/**
337
	 * process the common
338
	 *
339
	 * @since 4.00
340
	 *
341
	 * @return string|null
342
	 */
343
344
	protected function _processCommon() : ?string
345
	{
346
		$adminParameter = $this->getAdmin();
347
		$commonArray =
348
		[
349
			'enable',
350
			'disable',
351
			'publish',
352
			'unpublish',
353
			'install',
354
			'uninstall',
355
			'delete'
356
		];
357
		if (in_array($adminParameter, $commonArray))
358
		{
359
			$commonController = new Admin\Controller\Common($this->_registry, $this->_request, $this->_language, $this->_config);
360
			return $commonController->process($adminParameter);
361
		}
362
		return null;
363
	}
364
365
	/**
366
	 * render the view
367
	 *
368
	 * @since 3.3.0
369
	 *
370
	 * @return string|null
371
	 */
372
373
	protected function _renderView() : ?string
374
	{
375
		$tableParameter = $this->getTable();
376
377
		/* handle table */
378
379
		if ($tableParameter === 'categories')
380
		{
381
			$categoryTable = new Admin\View\CategoryTable($this->_registry, $this->_language);
382
			return $categoryTable->render();
383
		}
384
		if ($tableParameter === 'articles')
385
		{
386
			$articleTable = new Admin\View\ArticleTable($this->_registry, $this->_language);
387
			return $articleTable->render();
388
		}
389
		if ($tableParameter === 'extras')
390
		{
391
			$extraTable = new Admin\View\ExtraTable($this->_registry, $this->_language);
392
			return $extraTable->render();
393
		}
394
		if ($tableParameter === 'comments')
395
		{
396
			$commentTable = new Admin\View\CommentTable($this->_registry, $this->_language);
397
			return $commentTable->render();
398
		}
399
		if ($tableParameter === 'users')
400
		{
401
			$userTable = new Admin\View\UserTable($this->_registry, $this->_language);
402
			return $userTable->render();
403
		}
404
		if ($tableParameter === 'groups')
405
		{
406
			$groupTable = new Admin\View\GroupTable($this->_registry, $this->_language);
407
			return $groupTable->render();
408
		}
409
		if ($tableParameter === 'modules')
410
		{
411
			$moduleTable = new Admin\View\ModuleTable($this->_registry, $this->_language);
412
			return $moduleTable->render();
413
		}
414
		return null;
415
	}
416
417
	/**
418
	 * render the new
419
	 *
420
	 * @since 3.3.0
421
	 *
422
	 * @return string|null
423
	 */
424
425
	protected function _renderNew() : ?string
426
	{
427
		$tableParameter = $this->getTable();
428
429
		/* handle table */
430
431
		if ($tableParameter === 'categories')
432
		{
433
			$categoryForm = new Admin\View\CategoryForm($this->_registry, $this->_language);
434
			return $categoryForm->render();
435
		}
436
		if ($tableParameter === 'articles')
437
		{
438
			$articleForm = new Admin\View\ArticleForm($this->_registry, $this->_language);
439
			return $articleForm->render();
440
		}
441
		if ($tableParameter === 'extras')
442
		{
443
			$extraForm = new Admin\View\ExtraForm($this->_registry, $this->_language);
444
			return $extraForm->render();
445
		}
446
		if ($tableParameter === 'comments')
447
		{
448
			$commentForm = new Admin\View\CommentForm($this->_registry, $this->_language);
449
			return $commentForm->render();
450
		}
451
		if ($tableParameter === 'users')
452
		{
453
			$userForm = new Admin\View\UserForm($this->_registry, $this->_language);
454
			return $userForm->render();
455
		}
456
		if ($tableParameter === 'groups')
457
		{
458
			$groupForm = new Admin\View\GroupForm($this->_registry, $this->_language);
459
			return $groupForm->render();
460
		}
461
		return null;
462
	}
463
464
	/**
465
	 * render the edit
466
	 *
467
	 * @since 3.3.0
468
	 *
469
	 * @return string|null
470
	 */
471
472
	protected function _renderEdit() : ?string
473
	{
474
		$tableParameter = $this->getTable();
475
		$idParameter = $this->getId();
476
477
		/* handle table */
478
479
		if ($tableParameter === 'categories' && $idParameter)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $idParameter of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
480
		{
481
			$categoryForm = new Admin\View\CategoryForm($this->_registry, $this->_language);
482
			return $categoryForm->render($idParameter);
483
		}
484
		if ($tableParameter === 'articles' && $idParameter)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $idParameter of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
485
		{
486
			$articleForm = new Admin\View\ArticleForm($this->_registry, $this->_language);
487
			return $articleForm->render($idParameter);
488
		}
489
		if ($tableParameter === 'extras' && $idParameter)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $idParameter of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
490
		{
491
			$extraForm = new Admin\View\ExtraForm($this->_registry, $this->_language);
492
			return $extraForm->render($idParameter);
493
		}
494
		if ($tableParameter === 'comments' && $idParameter)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $idParameter of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
495
		{
496
			$commentForm = new Admin\View\CommentForm($this->_registry, $this->_language);
497
			return $commentForm->render($idParameter);
498
		}
499
		if ($tableParameter === 'users' && $idParameter)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $idParameter of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
500
		{
501
			$userForm = new Admin\View\UserForm($this->_registry, $this->_language);
502
			return $userForm->render($idParameter);
503
		}
504
		if ($tableParameter === 'groups' && $idParameter)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $idParameter of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
505
		{
506
			$groupForm = new Admin\View\GroupForm($this->_registry, $this->_language);
507
			return $groupForm->render($idParameter);
508
		}
509
		if ($tableParameter === 'modules' && $idParameter)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $idParameter of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
510
		{
511
			$moduleForm = new Admin\View\ModuleForm($this->_registry, $this->_language);
512
			return $moduleForm->render($idParameter);
513
		}
514
		if ($tableParameter === 'settings')
515
		{
516
			$settingForm = new Admin\View\SettingForm($this->_registry, $this->_language);
517
			return $settingForm->render();
518
		}
519
		return null;
520
	}
521
522
	/**
523
	 * messenger factory
524
	 *
525
	 * @since 4.0.0
526
	 *
527
	 * @return Admin\View\Helper\Messenger
528
	 */
529 1
530
	protected function _messengerFactory() : Admin\View\Helper\Messenger
531 1
	{
532
		return new Admin\View\Helper\Messenger($this->_registry);
533
	}
534
535
	/**
536
	 * show the token error
537
	 *
538
	 * @since 3.3.0
539
	 *
540
	 * @return string
541
	 */
542 1
543
	protected function _errorToken() : string
544 1
	{
545
		$messenger = $this->_messengerFactory();
546 1
		return $messenger
547 1
			->setRoute($this->_language->get('back'), 'admin')
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('back') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\View\Helper\Messenger::setRoute() 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...
548
			->error($this->_language->get('token_incorrect'), $this->_language->get('error_occurred'));
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('error_occurred') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\View\Helper\Messenger::error() 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...
549
	}
550
551
	/**
552
	 * show the access error
553
	 *
554
	 * @since 3.3.0
555
	 *
556
	 * @return string
557
	 */
558
559
	protected function _errorAccess() : string
560
	{
561
		$messenger = $this->_messengerFactory();
562
		return $messenger
563
			->setRoute($this->_language->get('back'), 'admin')
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('back') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\View\Helper\Messenger::setRoute() 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...
564
			->error($this->_language->get('access_no'), $this->_language->get('error_occurred'));
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $this->_language->get('error_occurred') targeting Redaxscript\Language::get() can also be of type array; however, Redaxscript\View\Helper\Messenger::error() 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...
565
	}
566
}
567