Completed
Push — master ( da58d4...61a0f7 )
by Henry
06:34
created

ControllerAbstract::_normalizePost()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 1
nop 1
crap 3
1
<?php
2
namespace Redaxscript\Controller;
3
4
use Redaxscript\Config;
5
use Redaxscript\Language;
6
use Redaxscript\Registry;
7
use Redaxscript\Request;
8
use Redaxscript\View;
9
use function array_map;
10
11
/**
12
 * abstract class to create a controller class
13
 *
14
 * @since 3.0.0
15
 *
16
 * @package Redaxscript
17
 * @category Controller
18
 * @author Henry Ruhs
19
 */
20
21
abstract class ControllerAbstract implements ControllerInterface
22
{
23
	/**
24
	 * instance of the registry class
25
	 *
26
	 * @var Registry
27
	 */
28
29
	protected $_registry;
30
31
	/**
32
	 * instance of the request class
33
	 *
34
	 * @var Request
35
	 */
36
37
	protected $_request;
38
39
	/**
40
	 * instance of the language class
41
	 *
42
	 * @var Language
43
	 */
44
45
	protected $_language;
46
47
	/**
48
	 * instance of the config class
49
	 *
50
	 * @var Config
51
	 */
52
53
	protected $_config;
54
55
	/**
56
	 * constructor of the class
57
	 *
58
	 * @since 3.0.0
59
	 *
60
	 * @param Registry $registry instance of the registry class
61
	 * @param Request $request instance of the request class
62
	 * @param Language $language instance of the language class
63
	 * @param Config $config instance of the config class
64
	 */
65
66 54
	public function __construct(Registry $registry, Request $request, Language $language, Config $config)
67
	{
68 54
		$this->_registry = $registry;
69 54
		$this->_request = $request;
70 54
		$this->_language = $language;
71 54
		$this->_config = $config;
72 54
	}
73
74
	/**
75
	 * messenger factory
76
	 *
77
	 * @since 4.0.0
78
	 *
79
	 * @return View\Helper\Messenger
80
	 */
81
82 42
	protected function _messengerFactory() : View\Helper\Messenger
83
	{
84 42
		return new View\Helper\Messenger($this->_registry);
85
	}
86
87
	/**
88
	 * normalize the post
89
	 *
90
	 * @since 4.0.0
91
	 *
92
	 * @param array $postArray array of the post
93
	 *
94
	 * @return array|null
95
	 */
96
97 36
	protected function _normalizePost(array $postArray = []) : ?array
98
	{
99
		return array_map(function($value)
100
		{
101 36
			return $value === 'null' || $value === '' ? null : $value;
102 36
		}, $postArray);
103
	}
104
105
	/**
106
	 * show the success
107
	 *
108
	 * @since 4.0.0
109
	 *
110
	 * @param array $successArray array of the success
111
	 *
112
	 * @return string
113
	 */
114
115 8
	protected function _success(array $successArray = []) : string
116
	{
117 8
		$messenger = $this->_messengerFactory();
118
		return $messenger
119 8
			->setRoute($this->_language->get('continue'), $successArray['route'])
0 ignored issues
show
Bug introduced by
It seems like $this->_language->get('continue') 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...
120 8
			->doRedirect($successArray['timeout'])
121 8
			->success($successArray['message'] ? : $this->_language->get('operation_completed'), $successArray['title'] ? : $this->_language->get('success'));
122
	}
123
124
	/**
125
	 * show the info
126
	 *
127
	 * @since 4.0.0
128
	 *
129
	 * @param array $infoArray array of the info
130
	 *
131
	 * @return string
132
	 */
133
134
	protected function _info(array $infoArray = []) : string
135
	{
136
		$messenger = $this->_messengerFactory();
137
		return $messenger
138
			->setRoute($this->_language->get('continue'), $infoArray['route'])
0 ignored issues
show
Bug introduced by
It seems like $this->_language->get('continue') 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...
139
			->doRedirect($infoArray['timeout'])
140
			->warning($infoArray['message'] ? : $this->_language->get('something_wrong'), $infoArray['title'] ? : $this->_language->get('info'));
141
	}
142
143
	/**
144
	 * show the warning
145
	 *
146
	 * @since 4.0.0
147
	 *
148
	 * @param array $warningArray array of the warning
149
	 *
150
	 * @return string
151
	 */
152
153 1
	protected function _warning(array $warningArray = []) : string
154
	{
155 1
		$messenger = $this->_messengerFactory();
156
		return $messenger
157 1
			->setRoute($this->_language->get('continue'), $warningArray['route'])
0 ignored issues
show
Bug introduced by
It seems like $this->_language->get('continue') 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...
158 1
			->doRedirect($warningArray['timeout'])
159 1
			->warning($warningArray['message'] ? : $this->_language->get('something_wrong'), $warningArray['title'] ? : $this->_language->get('warning'));
160
	}
161
162
	/**
163
	 * show the error
164
	 *
165
	 * @since 4.0.0
166
	 *
167
	 * @param array $errorArray array of the error
168
	 *
169
	 * @return string
170
	 */
171
172 21
	protected function _error(array $errorArray = []) : string
173
	{
174 21
		$messenger = $this->_messengerFactory();
175
		return $messenger
176 21
			->setRoute($this->_language->get('back'), $errorArray['route'])
0 ignored issues
show
Bug introduced by
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...
177 21
			->error($errorArray['message'] ? : $this->_language->get('something_wrong'), $errorArray['title'] ? : $this->_language->get('error'));
178
	}
179
}
180