Completed
Push — master ( 1da492...320203 )
by Henry
07:00
created

includes/View/SystemStatus.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
	public function render() : ?string
29
	{
30
		$output = null;
31
32
		/* handle error */
33
34
		$messageArray = $this->_validateError();
35
		if ($messageArray)
0 ignored issues
show
Bug Best Practice introduced by
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
			$output .= $this->_error(
38
			[
39
				'message' => $messageArray
40
			]);
41
		}
42
43
		/* handle warning */
44
45
		$messageArray = $this->_validateWarning();
46
		if ($messageArray)
0 ignored issues
show
Bug Best Practice introduced by
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
			$output .= $this->_warning(
49
			[
50
				'message' => $messageArray
51
			]);
52
		}
53
		return $output;
54
	}
55
56
	/**
57
	 * validate the error
58
	 *
59
	 * @since 3.0.0
60
	 *
61
	 * @return array
62
	 */
63
64
	protected function _validateError() : array
65
	{
66
		$messageArray = [];
67
		if (!$this->_registry->get('dbStatus'))
68
		{
69
			$messageArray[] = $this->_language->get('database_failed');
70
		}
71
		if (!$this->_registry->get('phpStatus'))
72
		{
73
			$messageArray[] = $this->_language->get('php_version_unsupported');
74
		}
75
		if (!$this->_registry->get('driverArray'))
76
		{
77
			$messageArray[] = $this->_language->get('pdo_driver_disabled');
78
		}
79
		if (!$this->_registry->get('sessionStatus'))
80
		{
81
			$messageArray[] = $this->_language->get('session_disabled');
82
		}
83
		return $messageArray;
84
	}
85
86
	/**
87
	 * validate the warning
88
	 *
89
	 * @since 3.0.0
90
	 *
91
	 * @return array
92
	 */
93
94
	protected function _validateWarning() : array
95
	{
96
		$messageArray = [];
97
		$phpOs = $this->_registry->get('phpOs');
98
		$moduleArray = $this->_registry->get('moduleArray');
99
		$testOsArray =
100
		[
101
			'linux',
102
			'windows'
103
		];
104
		$testModuleArray =
105
		[
106
			'mod_brotli',
107
			'mod_deflate',
108
			'mod_headers',
109
			'mod_rewrite'
110
		];
111
		if (!in_array($phpOs, $testOsArray))
112
		{
113
			$messageArray[] = $this->_language->get('php_os_unsupported');
114
		}
115
116
		/* process modules */
117
118
		foreach ($testModuleArray as $value)
119
		{
120
			if (!is_array($moduleArray) || !in_array($value, $moduleArray))
121
			{
122
				$messageArray[] = $this->_language->get('apache_module_disabled') . $this->_language->get('colon') . ' ' . $value;
123
			}
124
		}
125
		return $messageArray;
126
	}
127
128
	/**
129
	 * messenger factory
130
	 *
131
	 * @since 4.0.0
132
	 *
133
	 * @return View\Helper\Messenger
134
	 */
135
136
	protected function _messengerFactory() : View\Helper\Messenger
137
	{
138
		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
	protected function _error(array $errorArray = []) : string
152
	{
153
		$messenger = $this->_messengerFactory();
154
		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
	protected function _warning(array $warningArray = []) : string
168
	{
169
		$messenger = $this->_messengerFactory();
170
		return $messenger->warning($warningArray['message']);
171
	}
172
}
173