Common::process()   F
last analyzed

Complexity

Conditions 15
Paths 255

Size

Total Lines 111

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 0
Metric Value
dl 0
loc 111
ccs 0
cts 41
cp 0
rs 3.5166
c 0
b 0
f 0
cc 15
nc 255
nop 1
crap 240

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Redaxscript\Admin\Controller;
3
4
use Redaxscript\Admin;
5
use function method_exists;
6
7
/**
8
 * children class to handle common
9
 *
10
 * @since 4.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Controller
14
 * @author Henry Ruhs
15
 */
16
17
class Common extends ControllerAbstract
18
{
19
	/**
20
	 * process the class
21
	 *
22
	 * @since 4.0.0
23
	 *
24
	 * @param string $action action to process
25
	 *
26
	 * @return string
27
	 */
28
29
	public function process(string $action = null) : string
30
	{
31
		$table = $this->_registry->get('tableParameter');
32
		$id = $this->_registry->get('idParameter');
33
		$alias = $this->_registry->get('aliasParameter');
34
35
		/* handle publish */
36
37
		if ($action === 'publish')
38
		{
39
			if ($this->_publish($table, $id))
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_publish() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by Henry Ruhs
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_publish() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
40
			{
41
				return $this->_success(
42
				[
43
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by redaxmedia
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
44
					'timeout' => 0
45
				]);
46
			}
47
		}
48
49
		/* handle unpublish */
50
51
		if ($action === 'unpublish')
52
		{
53
			if ($this->_unpublish($table, $id))
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_unpublish() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by Henry Ruhs
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_unpublish() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
54
			{
55
				return $this->_success(
56
				[
57
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by redaxmedia
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
58
					'timeout' => 0
59
				]);
60
			}
61
		}
62
63
		/* handle enable */
64
65
		if ($action === 'enable')
66
		{
67
			if ($this->_enable($table, $id))
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_enable() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by Henry Ruhs
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_enable() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
68
			{
69
				return $this->_success(
70
				[
71
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by redaxmedia
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
72
					'timeout' => 0
73
				]);
74
			}
75
		}
76
77
		/* handle disable */
78
79
		if ($action === 'disable')
80
		{
81
			if ($this->_disable($table, $id))
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_disable() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by Henry Ruhs
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_disable() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
82
			{
83
				return $this->_success(
84
				[
85
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by redaxmedia
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
86
					'timeout' => 0
87
				]);
88
			}
89
		}
90
91
		/* handle install */
92
93
		if ($action === 'install')
94
		{
95
			if ($this->_install($table, $alias))
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_install() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by Henry Ruhs
It seems like $alias defined by $this->_registry->get('aliasParameter') on line 33 can also be of type array; however, Redaxscript\Admin\Controller\Common::_install() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
96
			{
97
				return $this->_success(
98
				[
99
					'route' => $this->_getRoute($table),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
100
					'timeout' => 0
101
				]);
102
			}
103
		}
104
105
		/* handle uninstall */
106
107
		if ($action === 'uninstall')
108
		{
109
			if ($this->_uninstall($table, $alias))
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_uninstall() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by Henry Ruhs
It seems like $alias defined by $this->_registry->get('aliasParameter') on line 33 can also be of type array; however, Redaxscript\Admin\Controller\Common::_uninstall() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
110
			{
111
				return $this->_success(
112
				[
113
					'route' => $this->_getRoute($table),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
114
					'timeout' => 0
115
				]);
116
			}
117
		}
118
119
		/* handle delete */
120
121
		if ($action === 'delete')
122
		{
123
			if ($this->_delete($table, $id))
0 ignored issues
show
Bug introduced by Henry Ruhs
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_delete() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by Henry Ruhs
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_delete() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
124
			{
125
				return $this->_success(
126
				[
127
					'route' => $this->_getRoute($table, $id),
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by redaxmedia
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
128
					'timeout' => 0
129
				]);
130
			}
131
		}
132
133
		/* handle error */
134
135
		return $this->_error(
136
		[
137
			'route' => $this->_getRoute($table, $id)
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $table defined by $this->_registry->get('tableParameter') on line 31 can also be of type array; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by redaxmedia
It seems like $id defined by $this->_registry->get('idParameter') on line 32 can also be of type array or string; however, Redaxscript\Admin\Controller\Common::_getRoute() does only seem to accept null|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
138
		]);
139
	}
140
141
	/**
142
	 * publish the item
143
	 *
144
	 * @since 4.0.0
145
	 *
146
	 * @param string $table name of the table
147
	 * @param int $id identifier of the item
148
	 *
149
	 * @return bool
150
	 */
151
152
	protected function _publish(string $table = null, int $id = null) : bool
153
	{
154
		if ($table === 'categories')
155
		{
156
			$categoryModel = new Admin\Model\Category();
157
			return $categoryModel->publishById($id);
158
		}
159
		if ($table === 'articles')
160
		{
161
			$articleModel = new Admin\Model\Article();
162
			return $articleModel->publishById($id);
163
		}
164
		if ($table === 'extras')
165
		{
166
			$extraModel = new Admin\Model\Extra();
167
			return $extraModel->publishById($id);
168
		}
169
		if ($table === 'comments')
170
		{
171
			$commentModel = new Admin\Model\Comment();
172
			return $commentModel->publishById($id);
173
		}
174
		return false;
175
	}
176
177
	/**
178
	 * unpublish the item
179
	 *
180
	 * @since 4.0.0
181
	 *
182
	 * @param string $table name of the table
183
	 * @param int $id identifier of the item
184
	 *
185
	 * @return bool
186
	 */
187
188
	protected function _unpublish(string $table = null, int $id = null) : bool
189
	{
190
		if ($table === 'categories')
191
		{
192
			$categoryModel = new Admin\Model\Category();
193
			return $categoryModel->unpublishById($id);
194
		}
195
		if ($table === 'articles')
196
		{
197
			$articleModel = new Admin\Model\Article();
198
			return $articleModel->unpublishById($id);
199
		}
200
		if ($table === 'extras')
201
		{
202
			$extraModel = new Admin\Model\Extra();
203
			return $extraModel->unpublishById($id);
204
		}
205
		if ($table === 'comments')
206
		{
207
			$commentModel = new Admin\Model\Comment();
208
			return $commentModel->unpublishById($id);
209
		}
210
		return false;
211
	}
212
213
	/**
214
	 * enable the item
215
	 *
216
	 * @since 4.0.0
217
	 *
218
	 * @param string $table name of the table
219
	 * @param int $id identifier of the item
220
	 *
221
	 * @return bool
222
	 */
223
224
	protected function _enable(string $table = null, int $id = null) : bool
225
	{
226
		if ($table === 'groups')
227
		{
228
			$groupModel = new Admin\Model\Group();
229
			return $groupModel->enableById($id);
230
		}
231
		if ($table === 'users')
232
		{
233
			$userModel = new Admin\Model\User();
234
			return $userModel->enableById($id);
235
		}
236
		if ($table === 'modules')
237
		{
238
			$moduleModel = new Admin\Model\Module();
239
			return $moduleModel->enableById($id);
240
		}
241
		return false;
242
	}
243
244
	/**
245
	 * disable the item
246
	 *
247
	 * @since 4.0.0
248
	 *
249
	 * @param string $table name of the table
250
	 * @param int $id identifier of the item
251
	 *
252
	 * @return bool
253
	 */
254
255
	protected function _disable(string $table = null, int $id = null) : bool
256
	{
257
		if ($table === 'groups')
258
		{
259
			$groupModel = new Admin\Model\Group();
260
			return $groupModel->disableById($id);
261
		}
262
		if ($table === 'users')
263
		{
264
			$userModel = new Admin\Model\User();
265
			return $userModel->disableById($id);
266
		}
267
		if ($table === 'modules')
268
		{
269
			$moduleModel = new Admin\Model\Module();
270
			return $moduleModel->disableById($id);
271
		}
272
		return false;
273
	}
274
275
	/**
276
	 * install the item
277
	 *
278
	 * @since 4.0.0
279
	 *
280
	 * @param string $table name of the table
281
	 * @param string $alias alias of the item
282
	 *
283
	 * @return bool
284
	 */
285
286
	protected function _install(string $table = null, string $alias = null) : bool
287
	{
288
		if ($table === 'modules')
289
		{
290
			$moduleClass = 'Redaxscript\Modules\\' . $alias . '\\' . $alias;
291
			if (method_exists($moduleClass, 'install'))
292
			{
293
				$module = new $moduleClass($this->_registry, $this->_request, $this->_language, $this->_config);
294
				return $module->install();
295
			}
296
		}
297
		return false;
298
	}
299
300
	/**
301
	 * uninstall the item
302
	 *
303
	 * @since 4.0.0
304
	 *
305
	 * @param string $table name of the table
306
	 * @param string $alias alias of the item
307
	 *
308
	 * @return bool
309
	 */
310
311
	protected function _uninstall(string $table = null, string $alias = null) : bool
312
	{
313
		if ($table === 'modules')
314
		{
315
			$moduleClass = 'Redaxscript\Modules\\' . $alias . '\\' . $alias;
316
			if (method_exists($moduleClass, 'uninstall'))
317
			{
318
				$module = new $moduleClass($this->_registry, $this->_request, $this->_language, $this->_config);
319
				return $module->uninstall();
320
			}
321
		}
322
		return false;
323
	}
324
325
	/**
326
	 * delete the item
327
	 *
328
	 * @since 4.0.0
329
	 *
330
	 * @param string $table name of the table
331
	 * @param int $id identifier of the item
332
	 *
333
	 * @return bool
334
	 */
335
336
	protected function _delete(string $table = null, int $id = null) : bool
337
	{
338
		if ($table === 'categories')
339
		{
340
			$categoryModel = new Admin\Model\Category();
341
			return $categoryModel->deleteById($id);
342
		}
343
		if ($table === 'articles')
344
		{
345
			$articleModel = new Admin\Model\Article();
346
			return $articleModel->deleteById($id);
347
		}
348
		if ($table === 'extras')
349
		{
350
			$extraModel = new Admin\Model\Extra();
351
			return $extraModel->deleteById($id);
352
		}
353
		if ($table === 'comments')
354
		{
355
			$commentModel = new Admin\Model\Comment();
356
			return $commentModel->deleteById($id);
357
		}
358
		if ($table === 'groups')
359
		{
360
			$groupModel = new Admin\Model\Group();
361
			return $groupModel->deleteById($id);
362
		}
363
		if ($table === 'users')
364
		{
365
			$userModel = new Admin\Model\User();
366
			return $userModel->deleteById($id);
367
		}
368
		return false;
369
	}
370
371
	/**
372
	 * get the route
373
	 *
374
	 * @since 4.0.0
375
	 *
376
	 * @param string $table name of the table
377
	 * @param int $id identifier of the item
378
	 *
379
	 * @return string
380
	 */
381
382
	protected function _getRoute(string $table = null, int $id = null) : string
383
	{
384
		if ($this->_registry->get($table . 'Edit'))
385
		{
386
			if ($id)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $id of type null|integer 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...
387
			{
388
				return 'admin/view/' . $table . '#row-' . $id;
389
			}
390
			if ($table)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $table of type null|string 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...
391
			{
392
				return 'admin/view/' . $table;
393
			}
394
		}
395
		return 'admin';
396
	}
397
}
398