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 | 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
|
|||
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
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
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 |
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.