Completed
Branch master (e57f9b)
by Daniel
03:01
created
Category
source/Compare.php 1 patch
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
     public function __construct()
47 47
     {
48 48
         $this->getConfiguration();
49
-        $this->applicationFlags      = [
49
+        $this->applicationFlags = [
50 50
             'available_languages' => [
51 51
                 'en_US' => 'EN',
52 52
                 'ro_RO' => 'RO',
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
             'default_language'    => 'ro_RO',
55 55
             'name'                => 'Info-Compare'
56 56
         ];
57
-        $urlToGetLbl                 = $this->config['Servers'][$this->config['Defaults']['Source']]['url']
57
+        $urlToGetLbl                 = $this->config[ 'Servers' ][ $this->config[ 'Defaults' ][ 'Source' ] ][ 'url' ]
58 58
             . '?Label=---' . urlencode(' List of known labels');
59
-        $knownLabels                 = $this->getContentFromUrlThroughCurlAsArrayIfJson($urlToGetLbl)['response'];
60
-        $this->informatorKnownLabels = array_diff($knownLabels, ['--- List of known labels']);
59
+        $knownLabels                 = $this->getContentFromUrlThroughCurlAsArrayIfJson($urlToGetLbl)[ 'response' ];
60
+        $this->informatorKnownLabels = array_diff($knownLabels, [ '--- List of known labels' ]);
61 61
         echo $this->setHeaderHtml();
62 62
         $this->setDefaultOptions();
63 63
         echo $this->setFormOptions();
64
-        if (isset($_GET['Label'])) {
64
+        if (isset($_GET[ 'Label' ])) {
65 65
             $this->processInfos();
66 66
             echo $this->setFormCurlInfos();
67 67
             echo $this->setFormInfos();
@@ -74,40 +74,40 @@  discard block
 block discarded – undo
74 74
         if ((!is_array($firstArray)) || (!is_array($secondArray))) {
75 75
             return '';
76 76
         }
77
-        $firstRow     = $this->mergeArraysIntoFirstSecond($firstArray, $secondArray, ['first', 'second']);
78
-        $secondRow    = $this->mergeArraysIntoFirstSecond($secondArray, $firstArray, ['second', 'first']);
77
+        $firstRow     = $this->mergeArraysIntoFirstSecond($firstArray, $secondArray, [ 'first', 'second' ]);
78
+        $secondRow    = $this->mergeArraysIntoFirstSecond($secondArray, $firstArray, [ 'second', 'first' ]);
79 79
         $row          = array_merge($firstRow, $secondRow);
80 80
         ksort($row);
81
-        $urlArguments = '?Label=' . $_REQUEST['Label'];
82
-        $sString[]    = '<table style="width:100%">'
81
+        $urlArguments = '?Label=' . $_REQUEST[ 'Label' ];
82
+        $sString[ ]    = '<table style="width:100%">'
83 83
             . '<thead><tr>'
84 84
             . '<th>Identifier</th>'
85
-            . '<th><a href="' . $this->config['Servers'][$_REQUEST['localConfig']]['url']
85
+            . '<th><a href="' . $this->config[ 'Servers' ][ $_REQUEST[ 'localConfig' ] ][ 'url' ]
86 86
             . $urlArguments . '" target="_blank">'
87
-            . $this->config['Servers'][$_REQUEST['localConfig']]['name'] . '</a></th>'
88
-            . '<th><a href="' . $this->config['Servers'][$_REQUEST['serverConfig']]['url']
87
+            . $this->config[ 'Servers' ][ $_REQUEST[ 'localConfig' ] ][ 'name' ] . '</a></th>'
88
+            . '<th><a href="' . $this->config[ 'Servers' ][ $_REQUEST[ 'serverConfig' ] ][ 'url' ]
89 89
             . $urlArguments . '" target="_blank">'
90
-            . $this->config['Servers'][$_REQUEST['serverConfig']]['name'] . '</a></th>'
90
+            . $this->config[ 'Servers' ][ $_REQUEST[ 'serverConfig' ] ][ 'name' ] . '</a></th>'
91 91
             . '</tr></thead>'
92 92
             . '<tbody>';
93
-        if ($_REQUEST['displayOnlyDifferent'] == '1') {
93
+        if ($_REQUEST[ 'displayOnlyDifferent' ] == '1') {
94 94
             $displayOnlyDifferent = true;
95 95
         } else {
96 96
             $displayOnlyDifferent = false;
97 97
         }
98 98
         foreach ($row as $key => $value) {
99 99
             $rowString = '<tr><td style="width:20%;">' . $key . '</td><td style="width:40%;">'
100
-                . str_replace(',', ', ', $value['first']) . '</td><td style="width:40%;">'
101
-                . str_replace(',', ', ', $value['second']) . '</td></tr>';
100
+                . str_replace(',', ', ', $value[ 'first' ]) . '</td><td style="width:40%;">'
101
+                . str_replace(',', ', ', $value[ 'second' ]) . '</td></tr>';
102 102
             if ($displayOnlyDifferent) {
103
-                if ($value['first'] != $value['second']) {
104
-                    $sString[] = $rowString;
103
+                if ($value[ 'first' ] != $value[ 'second' ]) {
104
+                    $sString[ ] = $rowString;
105 105
                 }
106 106
             } else {
107
-                $sString[] = $rowString;
107
+                $sString[ ] = $rowString;
108 108
             }
109 109
         }
110
-        $sString[] = '</tbody></table>';
110
+        $sString[ ] = '</tbody></table>';
111 111
         return implode('', $sString);
112 112
     }
113 113
 
@@ -116,20 +116,20 @@  discard block
 block discarded – undo
116 116
         $servers = explode('|', IC_SERVERS);
117 117
         foreach ($servers as $value) {
118 118
             $pieces                    = explode('=', $value);
119
-            $this->config['Servers'][] = [
120
-                'name' => $pieces[0],
121
-                'url'  => $pieces[1],
119
+            $this->config[ 'Servers' ][ ] = [
120
+                'name' => $pieces[ 0 ],
121
+                'url'  => $pieces[ 1 ],
122 122
             ];
123 123
         }
124
-        $serverNames                        = array_column($this->config['Servers'], 'name');
125
-        $this->config['Defaults']['Source'] = array_search(IC_SOURCE, $serverNames);
126
-        $this->config['Defaults']['Target'] = array_search(IC_TARGET, $serverNames);
127
-        $this->config['Defaults']['Label']  = IC_LABEL;
124
+        $serverNames                        = array_column($this->config[ 'Servers' ], 'name');
125
+        $this->config[ 'Defaults' ][ 'Source' ] = array_search(IC_SOURCE, $serverNames);
126
+        $this->config[ 'Defaults' ][ 'Target' ] = array_search(IC_TARGET, $serverNames);
127
+        $this->config[ 'Defaults' ][ 'Label' ]  = IC_LABEL;
128 128
     }
129 129
 
130
-    private function mergeArraysIntoFirstSecond($firstArray, $secondArray, $pSequence = ['first', 'second'])
130
+    private function mergeArraysIntoFirstSecond($firstArray, $secondArray, $pSequence = [ 'first', 'second' ])
131 131
     {
132
-        $row = [];
132
+        $row = [ ];
133 133
         foreach ($firstArray as $key => $value) {
134 134
             if (is_array($value)) {
135 135
                 foreach ($value as $key2 => $value2) {
@@ -138,39 +138,39 @@  discard block
 block discarded – undo
138 138
                             if (is_array($value3)) {
139 139
                                 foreach ($value3 as $key4 => $value4) {
140 140
                                     $keyCrt                      = $key . '_' . $key2 . '__' . $key3 . '__' . $key4;
141
-                                    $row[$keyCrt][$pSequence[0]] = $value4;
142
-                                    if (isset($secondArray[$key][$key2][$key3][$key4])) {
143
-                                        $row[$keyCrt][$pSequence[1]] = $secondArray[$key][$key2][$key3][$key4];
141
+                                    $row[ $keyCrt ][ $pSequence[ 0 ] ] = $value4;
142
+                                    if (isset($secondArray[ $key ][ $key2 ][ $key3 ][ $key4 ])) {
143
+                                        $row[ $keyCrt ][ $pSequence[ 1 ] ] = $secondArray[ $key ][ $key2 ][ $key3 ][ $key4 ];
144 144
                                     } else {
145
-                                        $row[$keyCrt][$pSequence[1]] = '';
145
+                                        $row[ $keyCrt ][ $pSequence[ 1 ] ] = '';
146 146
                                     }
147 147
                                 }
148 148
                             } else {
149 149
                                 $keyCrt                      = $key . '_' . $key2 . '__' . $key3;
150
-                                $row[$keyCrt][$pSequence[0]] = $value3;
151
-                                if (isset($secondArray[$key][$key2][$key3])) {
152
-                                    $row[$keyCrt][$pSequence[1]] = $secondArray[$key][$key2][$key3];
150
+                                $row[ $keyCrt ][ $pSequence[ 0 ] ] = $value3;
151
+                                if (isset($secondArray[ $key ][ $key2 ][ $key3 ])) {
152
+                                    $row[ $keyCrt ][ $pSequence[ 1 ] ] = $secondArray[ $key ][ $key2 ][ $key3 ];
153 153
                                 } else {
154
-                                    $row[$keyCrt][$pSequence[1]] = '';
154
+                                    $row[ $keyCrt ][ $pSequence[ 1 ] ] = '';
155 155
                                 }
156 156
                             }
157 157
                         }
158 158
                     } else {
159 159
                         $keyCrt                      = $key . '_' . $key2;
160
-                        $row[$keyCrt][$pSequence[0]] = $value2;
161
-                        if (isset($secondArray[$key][$key2])) {
162
-                            $row[$keyCrt][$pSequence[1]] = $secondArray[$key][$key2];
160
+                        $row[ $keyCrt ][ $pSequence[ 0 ] ] = $value2;
161
+                        if (isset($secondArray[ $key ][ $key2 ])) {
162
+                            $row[ $keyCrt ][ $pSequence[ 1 ] ] = $secondArray[ $key ][ $key2 ];
163 163
                         } else {
164
-                            $row[$keyCrt][$pSequence[1]] = '';
164
+                            $row[ $keyCrt ][ $pSequence[ 1 ] ] = '';
165 165
                         }
166 166
                     }
167 167
                 }
168 168
             } else {
169
-                $row[$key][$pSequence[0]] = $value;
170
-                if (isset($secondArray[$key])) {
171
-                    $row[$key][$pSequence[1]] = $secondArray[$key];
169
+                $row[ $key ][ $pSequence[ 0 ] ] = $value;
170
+                if (isset($secondArray[ $key ])) {
171
+                    $row[ $key ][ $pSequence[ 1 ] ] = $secondArray[ $key ];
172 172
                 } else {
173
-                    $row[$key][$pSequence[1]] = '';
173
+                    $row[ $key ][ $pSequence[ 1 ] ] = '';
174 174
                 }
175 175
             }
176 176
         }
@@ -179,41 +179,41 @@  discard block
 block discarded – undo
179 179
 
180 180
     private function processInfos()
181 181
     {
182
-        if (isset($_REQUEST['localConfig']) && isset($_REQUEST['serverConfig'])) {
183
-            $urlArguments              = '?Label=' . urlencode($_REQUEST['Label']);
184
-            $source                    = $this->config['Servers'][$_REQUEST['localConfig']]['url'] . $urlArguments;
182
+        if (isset($_REQUEST[ 'localConfig' ]) && isset($_REQUEST[ 'serverConfig' ])) {
183
+            $urlArguments              = '?Label=' . urlencode($_REQUEST[ 'Label' ]);
184
+            $source                    = $this->config[ 'Servers' ][ $_REQUEST[ 'localConfig' ] ][ 'url' ] . $urlArguments;
185 185
             $this->localConfiguration  = $this->getContentFromUrlThroughCurlAsArrayIfJson($source);
186
-            $destination               = $this->config['Servers'][$_REQUEST['serverConfig']]['url'] . $urlArguments;
186
+            $destination               = $this->config[ 'Servers' ][ $_REQUEST[ 'serverConfig' ] ][ 'url' ] . $urlArguments;
187 187
             $this->serverConfiguration = $this->getContentFromUrlThroughCurlAsArrayIfJson($destination);
188 188
         } else {
189
-            $this->localConfiguration  = ['response' => '', 'info' => ''];
190
-            $this->serverConfiguration = ['response' => '', 'info' => ''];
189
+            $this->localConfiguration  = [ 'response' => '', 'info' => '' ];
190
+            $this->serverConfiguration = [ 'response' => '', 'info' => '' ];
191 191
         }
192 192
     }
193 193
 
194 194
     private function setDefaultOptions()
195 195
     {
196
-        if (!isset($_REQUEST['displayOnlyDifferent'])) {
197
-            $_REQUEST['displayOnlyDifferent'] = '1';
196
+        if (!isset($_REQUEST[ 'displayOnlyDifferent' ])) {
197
+            $_REQUEST[ 'displayOnlyDifferent' ] = '1';
198 198
         }
199
-        if (!isset($_REQUEST['localConfig'])) {
200
-            $_REQUEST['localConfig'] = $this->config['Defaults']['Source'];
199
+        if (!isset($_REQUEST[ 'localConfig' ])) {
200
+            $_REQUEST[ 'localConfig' ] = $this->config[ 'Defaults' ][ 'Source' ];
201 201
         }
202
-        if (!isset($_REQUEST['serverConfig'])) {
203
-            $_REQUEST['serverConfig'] = $this->config['Defaults']['Target'];
202
+        if (!isset($_REQUEST[ 'serverConfig' ])) {
203
+            $_REQUEST[ 'serverConfig' ] = $this->config[ 'Defaults' ][ 'Target' ];
204 204
         }
205
-        if (!isset($_REQUEST['Label'])) {
206
-            $_REQUEST['Label'] = $this->config['Defaults']['Label'];
205
+        if (!isset($_REQUEST[ 'Label' ])) {
206
+            $_REQUEST[ 'Label' ] = $this->config[ 'Defaults' ][ 'Label' ];
207 207
         }
208 208
     }
209 209
 
210 210
     private function setFooterHtml()
211 211
     {
212
-        $sReturn   = [];
213
-        $sReturn[] = '</div><!-- from main Tabber -->';
214
-        $sReturn[] = '<div class="resetOnly author">&copy; 2015 Daniel Popiniuc</div>';
215
-        $sReturn[] = '<hr/>';
216
-        $sReturn[] = '<div class="disclaimer">'
212
+        $sReturn   = [ ];
213
+        $sReturn[ ] = '</div><!-- from main Tabber -->';
214
+        $sReturn[ ] = '<div class="resetOnly author">&copy; 2015 Daniel Popiniuc</div>';
215
+        $sReturn[ ] = '<hr/>';
216
+        $sReturn[ ] = '<div class="disclaimer">'
217 217
             . 'The developer cannot be liable of any data input or results, '
218 218
             . 'included but not limited to any implication of these '
219 219
             . '(anywhere and whomever there might be these)!'
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
 
224 224
     private function setFormCurlInfos()
225 225
     {
226
-        $source      = $this->localConfiguration['info'];
227
-        $destination = $this->serverConfiguration['info'];
226
+        $source      = $this->localConfiguration[ 'info' ];
227
+        $destination = $this->serverConfiguration[ 'info' ];
228 228
         return '<div class="tabbertab" id="tabCurl" title="CURL infos">'
229 229
             . $this->displayTableFromMultiLevelArray($source, $destination)
230 230
             . '</div><!--from tabCurl-->';
@@ -232,10 +232,10 @@  discard block
 block discarded – undo
232 232
 
233 233
     private function setFormInfos()
234 234
     {
235
-        $source      = $this->localConfiguration['response'];
236
-        $destination = $this->serverConfiguration['response'];
235
+        $source      = $this->localConfiguration[ 'response' ];
236
+        $destination = $this->serverConfiguration[ 'response' ];
237 237
         return '<div class="tabbertab'
238
-            . (isset($_GET['Label']) ? ' tabbertabdefault' : '')
238
+            . (isset($_GET[ 'Label' ]) ? ' tabbertabdefault' : '')
239 239
             . '" id="tabConfigs" title="Informations">'
240 240
             . $this->displayTableFromMultiLevelArray($source, $destination)
241 241
             . '</div><!--from tabConfigs-->';
@@ -243,58 +243,58 @@  discard block
 block discarded – undo
243 243
 
244 244
     private function setFormOptions()
245 245
     {
246
-        $sReturn    = [];
247
-        $sReturn[]  = '<fieldset style="float:left;">'
246
+        $sReturn    = [ ];
247
+        $sReturn[ ]  = '<fieldset style="float:left;">'
248 248
             . '<legend>Type of results displayed</legend>'
249 249
             . '<input type="radio" name="displayOnlyDifferent" id="displayOnlyDifferent" value="1" '
250
-            . ($_REQUEST['displayOnlyDifferent'] == '1' ? 'checked ' : '') . '/>'
250
+            . ($_REQUEST[ 'displayOnlyDifferent' ] == '1' ? 'checked ' : '') . '/>'
251 251
             . '<label for="displayOnlyDifferent">Only the Different values</label>'
252 252
             . '<br/>'
253 253
             . '<input type="radio" name="displayOnlyDifferent" id="displayAll" value="0" '
254
-            . ($_REQUEST['displayOnlyDifferent'] == '0' ? 'checked ' : '') . '/>'
254
+            . ($_REQUEST[ 'displayOnlyDifferent' ] == '0' ? 'checked ' : '') . '/>'
255 255
             . '<label for="displayAll">All</label>'
256 256
             . '</fieldset>';
257
-        $tmpOptions = [];
258
-        foreach ($this->config['Servers'] as $key => $value) {
259
-            $tmpOptions[] = '<a href="' . $value['url'] . '" target="_blank">run-me</a>&nbsp;'
257
+        $tmpOptions = [ ];
258
+        foreach ($this->config[ 'Servers' ] as $key => $value) {
259
+            $tmpOptions[ ] = '<a href="' . $value[ 'url' ] . '" target="_blank">run-me</a>&nbsp;'
260 260
                 . '<input type="radio" name="localConfig" id="localConfig_'
261 261
                 . $key . '" value="' . $key . '" '
262
-                . ($_REQUEST['localConfig'] == $key ? 'checked ' : '')
262
+                . ($_REQUEST[ 'localConfig' ] == $key ? 'checked ' : '')
263 263
                 . '/><label for="localConfig_' . $key . '">'
264
-                . $value['name'] . '</label>';
264
+                . $value[ 'name' ] . '</label>';
265 265
         }
266
-        $sReturn[]  = '<fieldset style="float:left;">'
266
+        $sReturn[ ] = '<fieldset style="float:left;">'
267 267
             . '<legend>Source configuration providers</legend>'
268 268
             . implode('<br/>', $tmpOptions)
269 269
             . '</fieldset>';
270 270
         unset($tmpOptions);
271
-        $tmpOptions = [];
272
-        foreach ($this->config['Servers'] as $key => $value) {
273
-            $tmpOptions[] = '<a href="' . $value['url'] . '" target="_blank">run-me</a>&nbsp;'
271
+        $tmpOptions = [ ];
272
+        foreach ($this->config[ 'Servers' ] as $key => $value) {
273
+            $tmpOptions[ ] = '<a href="' . $value[ 'url' ] . '" target="_blank">run-me</a>&nbsp;'
274 274
                 . '<input type="radio" name="serverConfig" id="serverConfig_'
275
-                . $key . '" value="' . $key . '" ' . ($_REQUEST['serverConfig'] == $key ? 'checked ' : '') . '/>'
276
-                . '<label for="serverConfig_' . $key . '">' . $value['name'] . '</label>';
275
+                . $key . '" value="' . $key . '" ' . ($_REQUEST[ 'serverConfig' ] == $key ? 'checked ' : '') . '/>'
276
+                . '<label for="serverConfig_' . $key . '">' . $value[ 'name' ] . '</label>';
277 277
         }
278
-        $sReturn[]  = '<fieldset style="float:left;">'
278
+        $sReturn[ ] = '<fieldset style="float:left;">'
279 279
             . '<legend>Target configuration providers</legend>'
280 280
             . implode('<br/>', $tmpOptions)
281 281
             . '</fieldset>';
282 282
         unset($tmpOptions);
283
-        $tmpOptions = [];
283
+        $tmpOptions = [ ];
284 284
         foreach ($this->informatorKnownLabels as $value) {
285
-            $tmpOptions[] = '<input type="radio" name="Label" id="Label_' . $value . '" '
286
-                . 'value="' . $value . '" ' . ($_REQUEST['Label'] == $value ? 'checked ' : '') . '/>'
285
+            $tmpOptions[ ] = '<input type="radio" name="Label" id="Label_' . $value . '" '
286
+                . 'value="' . $value . '" ' . ($_REQUEST[ 'Label' ] == $value ? 'checked ' : '') . '/>'
287 287
                 . '<label for="Label_' . $value . '">' . $value . '</label>';
288 288
         }
289
-        $sReturn[] = '<fieldset style="float:left;">'
289
+        $sReturn[ ] = '<fieldset style="float:left;">'
290 290
             . '<legend>Informator Label to use</legend>'
291 291
             . implode('<br/>', $tmpOptions)
292 292
             . '</fieldset>';
293 293
         return '<div class="tabbertab'
294
-            . ((!isset($_REQUEST['localConfig']) && !isset($_REQUEST['serverConfig'])) ? ' tabbertabtabdefault' : '')
294
+            . ((!isset($_REQUEST[ 'localConfig' ]) && !isset($_REQUEST[ 'serverConfig' ])) ? ' tabbertabtabdefault' : '')
295 295
             . '" id="tabOptions" title="Options">'
296 296
             . '<style type="text/css" media="all" scoped>label { width: auto; }</style>'
297
-            . '<form method="get" action="' . $_SERVER['PHP_SELF'] . '">'
297
+            . '<form method="get" action="' . $_SERVER[ 'PHP_SELF' ] . '">'
298 298
             . '<input type="submit" value="Apply" />'
299 299
             . '<br/>' . implode('', $sReturn)
300 300
             . '</form>'
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
     {
307 307
         return $this->setHeaderCommon([
308 308
                 'lang'       => 'en-US',
309
-                'title'      => $this->applicationFlags['name'],
309
+                'title'      => $this->applicationFlags[ 'name' ],
310 310
                 'css'        => 'css/main.css',
311 311
                 'javascript' => 'js/tabber.min.js',
312 312
             ])
313 313
             . $this->setJavascriptContent('document.write(\'<style type="text/css">.tabber{display:none;}</style>\');')
314
-            . '<h1>' . $this->applicationFlags['name'] . '</h1>'
314
+            . '<h1>' . $this->applicationFlags[ 'name' ] . '</h1>'
315 315
             . '<div class="tabber" id="tab">'
316 316
         ;
317 317
     }
Please login to merge, or discard this patch.