SystemStatus   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 4
dl 0
loc 155
ccs 42
cts 42
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 27 3
A _validateError() 0 21 5
A _validateWarning() 0 33 5
A _messengerFactory() 0 4 1
A _error() 0 5 1
A _warning() 0 5 1
1
<?php
2
namespace Redaxscript\View;
3
4
use Redaxscript\View;
5
use function in_array;
6
use function is_array;
7
8
/**
9
 * children class to create the system status
10
 *
11
 * @since 3.0.0
12
 *
13
 * @package Redaxscript
14
 * @category View
15
 * @author Balázs Szilágyi
16
 */
17
18
class SystemStatus extends ViewAbstract
19
{
20
	/**
21
	 * render the view
22
	 *
23
	 * @since 3.0.0
24
	 *
25
	 * @return string|null
26
	 */
27
28 3
	public function render() : ?string
29
	{
30 3
		$output = null;
31
32
		/* handle error */
33
34 3
		$messageArray = $this->_validateError();
35 3
		if ($messageArray)
0 ignored issues
show
Bug Best Practice introduced by JimMorrison723
The expression $messageArray of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
36
		{
37 1
			$output .= $this->_error(
38
			[
39 1
				'message' => $messageArray
40
			]);
41
		}
42
43
		/* handle warning */
44
45 3
		$messageArray = $this->_validateWarning();
46 3
		if ($messageArray)
0 ignored issues
show
Bug Best Practice introduced by JimMorrison723
The expression $messageArray of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
47
		{
48 1
			$output .= $this->_warning(
49
			[
50 1
				'message' => $messageArray
51
			]);
52
		}
53 3
		return $output;
54
	}
55
56
	/**
57
	 * validate the error
58
	 *
59
	 * @since 3.0.0
60
	 *
61
	 * @return array
62
	 */
63
64 5
	protected function _validateError() : array
65
	{
66 5
		$messageArray = [];
67 5
		if (!$this->_registry->get('dbStatus'))
68
		{
69 2
			$messageArray[] = $this->_language->get('database_failed');
70
		}
71 5
		if (!$this->_registry->get('phpStatus'))
72
		{
73 1
			$messageArray[] = $this->_language->get('php_version_unsupported');
74
		}
75 5
		if (!$this->_registry->get('driverArray'))
76
		{
77 1
			$messageArray[] = $this->_language->get('pdo_driver_disabled');
78
		}
79 5
		if (!$this->_registry->get('sessionStatus'))
80
		{
81 1
			$messageArray[] = $this->_language->get('session_disabled');
82
		}
83 5
		return $messageArray;
84
	}
85
86
	/**
87
	 * validate the warning
88
	 *
89
	 * @since 3.0.0
90
	 *
91
	 * @return array
92
	 */
93
94 5
	protected function _validateWarning() : array
95
	{
96 5
		$messageArray = [];
97 5
		$phpOs = $this->_registry->get('phpOs');
98 5
		$moduleArray = $this->_registry->get('moduleArray');
99
		$testOsArray =
100
		[
101 5
			'linux',
102
			'windows'
103
		];
104
		$testModuleArray =
105
		[
106 5
			'mod_brotli',
107
			'mod_deflate',
108
			'mod_headers',
109
			'mod_rewrite'
110
		];
111 5
		if (!in_array($phpOs, $testOsArray))
112
		{
113 2
			$messageArray[] = $this->_language->get('php_os_unsupported');
114
		}
115
116
		/* process modules */
117
118 5
		foreach ($testModuleArray as $value)
119
		{
120 5
			if (!is_array($moduleArray) || !in_array($value, $moduleArray))
121
			{
122 1
				$messageArray[] = $this->_language->get('apache_module_disabled') . $this->_language->get('colon') . ' ' . $value;
123
			}
124
		}
125 5
		return $messageArray;
126
	}
127
128
	/**
129
	 * messenger factory
130
	 *
131
	 * @since 4.0.0
132
	 *
133
	 * @return View\Helper\Messenger
134
	 */
135
136 2
	protected function _messengerFactory() : View\Helper\Messenger
137
	{
138 2
		return new View\Helper\Messenger($this->_registry);
139
	}
140
141
	/**
142
	 * show the error
143
	 *
144
	 * @since 3.0.0
145
	 *
146
	 * @param array $errorArray
147
	 *
148
	 * @return string
149
	 */
150
151 1
	protected function _error(array $errorArray = []) : string
152
	{
153 1
		$messenger = $this->_messengerFactory();
154 1
		return $messenger->error($errorArray['message']);
155
	}
156
157
	/**
158
	 * show the warning
159
	 *
160
	 * @since 3.0.0
161
	 *
162
	 * @param array $warningArray
163
	 *
164
	 * @return string
165
	 */
166
167 1
	protected function _warning(array $warningArray = []) : string
168
	{
169 1
		$messenger = $this->_messengerFactory();
170 1
		return $messenger->warning($warningArray['message']);
171
	}
172
}
173