Passed
Push — 4.9 ( a180af...a86698 )
by Mikhail
01:52
created
app/Diff.php 3 patches
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -16,12 +16,12 @@  discard block
 block discarded – undo
16 16
 // A class containing functions for computing diffs and formatting the output.
17 17
 class Diff{
18 18
 
19
-  // define the constants
20
-  const UNMODIFIED = 0;
21
-  const DELETED    = 1;
22
-  const INSERTED   = 2;
19
+    // define the constants
20
+    const UNMODIFIED = 0;
21
+    const DELETED    = 1;
22
+    const INSERTED   = 2;
23 23
 
24
-  /* Returns the diff for two strings. The return value is an array, each of
24
+    /* Returns the diff for two strings. The return value is an array, each of
25 25
    * whose values is an array containing two values: a line (or character, if
26 26
    * $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the
27 27
    * line or character is in both strings), DIFF::DELETED (the line or character
@@ -33,34 +33,34 @@  discard block
 block discarded – undo
33 33
    * $compareCharacters - true to compare characters, and false to compare
34 34
    *                      lines; this optional parameter defaults to false
35 35
    */
36
-  public static function compare(
37
-      $string1, $string2, $compareCharacters = false){
36
+    public static function compare(
37
+        $string1, $string2, $compareCharacters = false){
38 38
 
39 39
     // initialise the sequences and comparison start and end positions
40 40
     $start = 0;
41 41
     if ($compareCharacters){
42
-      $sequence1 = $string1;
43
-      $sequence2 = $string2;
44
-      $end1 = strlen($string1) - 1;
45
-      $end2 = strlen($string2) - 1;
42
+        $sequence1 = $string1;
43
+        $sequence2 = $string2;
44
+        $end1 = strlen($string1) - 1;
45
+        $end2 = strlen($string2) - 1;
46 46
     }else{
47
-      $sequence1 = preg_split('/\R/', $string1);
48
-      $sequence2 = preg_split('/\R/', $string2);
49
-      $end1 = count($sequence1) - 1;
50
-      $end2 = count($sequence2) - 1;
47
+        $sequence1 = preg_split('/\R/', $string1);
48
+        $sequence2 = preg_split('/\R/', $string2);
49
+        $end1 = count($sequence1) - 1;
50
+        $end2 = count($sequence2) - 1;
51 51
     }
52 52
 
53 53
     // skip any common prefix
54 54
     while ($start <= $end1 && $start <= $end2
55 55
         && $sequence1[$start] == $sequence2[$start]){
56
-      $start ++;
56
+        $start ++;
57 57
     }
58 58
 
59 59
     // skip any common suffix
60 60
     while ($end1 >= $start && $end2 >= $start
61 61
         && $sequence1[$end1] == $sequence2[$end2]){
62
-      $end1 --;
63
-      $end2 --;
62
+        $end1 --;
63
+        $end2 --;
64 64
     }
65 65
 
66 66
     // compute the table of longest common subsequence lengths
@@ -73,29 +73,29 @@  discard block
 block discarded – undo
73 73
     // generate the full diff
74 74
     $diff = array();
75 75
     for ($index = 0; $index < $start; $index ++){
76
-      $diff[] = array($sequence1[$index], self::UNMODIFIED);
76
+        $diff[] = array($sequence1[$index], self::UNMODIFIED);
77 77
     }
78 78
     while (count($partialDiff) > 0) $diff[] = array_pop($partialDiff);
79 79
     for ($index = $end1 + 1;
80 80
         $index < ($compareCharacters ? strlen($sequence1) : count($sequence1));
81 81
         $index ++){
82
-      $diff[] = array($sequence1[$index], self::UNMODIFIED);
82
+        $diff[] = array($sequence1[$index], self::UNMODIFIED);
83 83
     }
84 84
 
85 85
     // return the diff
86 86
     return $diff;
87 87
 
88
-  }
88
+    }
89 89
 
90
-  /* Returns the diff for two files. The parameters are:
90
+    /* Returns the diff for two files. The parameters are:
91 91
    *
92 92
    * $file1             - the path to the first file
93 93
    * $file2             - the path to the second file
94 94
    * $compareCharacters - true to compare characters, and false to compare
95 95
    *                      lines; this optional parameter defaults to false
96 96
    */
97
-  public static function compareFiles(
98
-      $file1, $file2, $compareCharacters = false){
97
+    public static function compareFiles(
98
+        $file1, $file2, $compareCharacters = false){
99 99
 
100 100
     // return the diff of the files
101 101
     return self::compare(
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
         file_get_contents($file2),
104 104
         $compareCharacters);
105 105
 
106
-  }
106
+    }
107 107
 
108
-  /* Returns the table of longest common subsequence lengths for the specified
108
+    /* Returns the table of longest common subsequence lengths for the specified
109 109
    * sequences. The parameters are:
110 110
    *
111 111
    * $sequence1 - the first sequence
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
    * $end1      - the ending index for the first sequence
115 115
    * $end2      - the ending index for the second sequence
116 116
    */
117
-  private static function computeTable(
118
-      $sequence1, $sequence2, $start, $end1, $end2){
117
+    private static function computeTable(
118
+        $sequence1, $sequence2, $start, $end1, $end2){
119 119
 
120 120
     // determine the lengths to be compared
121 121
     $length1 = $end1 - $start + 1;
@@ -127,30 +127,30 @@  discard block
 block discarded – undo
127 127
     // loop over the rows
128 128
     for ($index1 = 1; $index1 <= $length1; $index1 ++){
129 129
 
130
-      // create the new row
131
-      $table[$index1] = array(0);
130
+        // create the new row
131
+        $table[$index1] = array(0);
132 132
 
133
-      // loop over the columns
134
-      for ($index2 = 1; $index2 <= $length2; $index2 ++){
133
+        // loop over the columns
134
+        for ($index2 = 1; $index2 <= $length2; $index2 ++){
135 135
 
136 136
         // store the longest common subsequence length
137 137
         if ($sequence1[$index1 + $start - 1]
138 138
             == $sequence2[$index2 + $start - 1]){
139
-          $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1;
139
+            $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1;
140 140
         }else{
141
-          $table[$index1][$index2] =
142
-              max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]);
141
+            $table[$index1][$index2] =
142
+                max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]);
143 143
         }
144 144
 
145
-      }
145
+        }
146 146
     }
147 147
 
148 148
     // return the table
149 149
     return $table;
150 150
 
151
-  }
151
+    }
152 152
 
153
-  /* Returns the partial diff for the specificed sequences, in reverse order.
153
+    /* Returns the partial diff for the specificed sequences, in reverse order.
154 154
    * The parameters are:
155 155
    *
156 156
    * $table     - the table returned by the computeTable function
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
    * $sequence2 - the second sequence
159 159
    * $start     - the starting index
160 160
    */
161
-  private static function generatePartialDiff(
162
-      $table, $sequence1, $sequence2, $start){
161
+    private static function generatePartialDiff(
162
+        $table, $sequence1, $sequence2, $start){
163 163
 
164 164
     //  initialise the diff
165 165
     $diff = array();
@@ -171,39 +171,39 @@  discard block
 block discarded – undo
171 171
     // loop until there are no items remaining in either sequence
172 172
     while ($index1 > 0 || $index2 > 0){
173 173
 
174
-      // check what has happened to the items at these indices
175
-      if ($index1 > 0 && $index2 > 0
174
+        // check what has happened to the items at these indices
175
+        if ($index1 > 0 && $index2 > 0
176 176
           && $sequence1[$index1 + $start - 1]
177
-              == $sequence2[$index2 + $start - 1]){
177
+                == $sequence2[$index2 + $start - 1]){
178 178
 
179 179
         // update the diff and the indices
180 180
         $diff[] = array($sequence1[$index1 + $start - 1], self::UNMODIFIED);
181 181
         $index1 --;
182 182
         $index2 --;
183 183
 
184
-      }elseif ($index2 > 0
184
+        }elseif ($index2 > 0
185 185
           && $table[$index1][$index2] == $table[$index1][$index2 - 1]){
186 186
 
187 187
         // update the diff and the indices
188 188
         $diff[] = array($sequence2[$index2 + $start - 1], self::INSERTED);
189 189
         $index2 --;
190 190
 
191
-      }else{
191
+        }else{
192 192
 
193 193
         // update the diff and the indices
194 194
         $diff[] = array($sequence1[$index1 + $start - 1], self::DELETED);
195 195
         $index1 --;
196 196
 
197
-      }
197
+        }
198 198
 
199 199
     }
200 200
 
201 201
     // return the diff
202 202
     return $diff;
203 203
 
204
-  }
204
+    }
205 205
 
206
-  /* Returns a diff as a string, where unmodified lines are prefixed by '  ',
206
+    /* Returns a diff as a string, where unmodified lines are prefixed by '  ',
207 207
    * deletions are prefixed by '- ', and insertions are prefixed by '+ '. The
208 208
    * parameters are:
209 209
    *
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
    * $separator - the separator between lines; this optional parameter defaults
212 212
    *              to "\n"
213 213
    */
214
-  public static function toString($diff, $separator = "\n"){
214
+    public static function toString($diff, $separator = "\n"){
215 215
 
216 216
     // initialise the string
217 217
     $string = '';
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
     // loop over the lines in the diff
220 220
     foreach ($diff as $line){
221 221
 
222
-      // extend the string with the line
223
-      switch ($line[1]){
222
+        // extend the string with the line
223
+        switch ($line[1]){
224 224
         case self::UNMODIFIED : $string .= '  ' . $line[0];break;
225 225
         case self::DELETED    : $string .= '- ' . $line[0];break;
226 226
         case self::INSERTED   : $string .= '+ ' . $line[0];break;
227
-      }
227
+        }
228 228
 
229
-      // extend the string with the separator
230
-      $string .= $separator;
229
+        // extend the string with the separator
230
+        $string .= $separator;
231 231
 
232 232
     }
233 233
 
234 234
     // return the string
235 235
     return $string;
236 236
 
237
-  }
237
+    }
238 238
 
239
-  /* Returns a diff as an HTML string, where unmodified lines are contained
239
+    /* Returns a diff as an HTML string, where unmodified lines are contained
240 240
    * within 'span' elements, deletions are contained within 'del' elements, and
241 241
    * insertions are contained within 'ins' elements. The parameters are:
242 242
    *
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
    * $separator - the separator between lines; this optional parameter defaults
245 245
    *              to '<br>'
246 246
    */
247
-  public static function toHTML($diff, $separator = '<br>'){
247
+    public static function toHTML($diff, $separator = '<br>'){
248 248
 
249 249
     // initialise the HTML
250 250
     $html = '';
@@ -252,28 +252,28 @@  discard block
 block discarded – undo
252 252
     // loop over the lines in the diff
253 253
     foreach ($diff as $line){
254 254
 
255
-      // extend the HTML with the line
256
-      switch ($line[1]){
255
+        // extend the HTML with the line
256
+        switch ($line[1]){
257 257
         case self::UNMODIFIED : $element = 'span'; break;
258 258
         case self::DELETED    : $element = 'del';  break;
259 259
         case self::INSERTED   : $element = 'ins';  break;
260
-      }
261
-      $html .=
262
-          '<' . $element . '>'
263
-          . htmlspecialchars($line[0])
264
-          . '</' . $element . '>';
260
+        }
261
+        $html .=
262
+            '<' . $element . '>'
263
+            . htmlspecialchars($line[0])
264
+            . '</' . $element . '>';
265 265
 
266
-      // extend the HTML with the separator
267
-      $html .= $separator;
266
+        // extend the HTML with the separator
267
+        $html .= $separator;
268 268
 
269 269
     }
270 270
 
271 271
     // return the HTML
272 272
     return $html;
273 273
 
274
-  }
274
+    }
275 275
 
276
-  /* Returns a diff as an HTML table. The parameters are:
276
+    /* Returns a diff as an HTML table. The parameters are:
277 277
    *
278 278
    * $diff        - the diff array
279 279
    * $indentation - indentation to add to every line of the generated HTML; this
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
    * $separator   - the separator between lines; this optional parameter
282 282
    *                defaults to '<br>'
283 283
    */
284
-  public static function toTable($diff, $indentation = '', $separator = '<br>'){
284
+    public static function toTable($diff, $indentation = '', $separator = '<br>'){
285 285
 
286 286
     // initialise the HTML
287 287
     $html = $indentation . "<table class=\"diff\">\n";
@@ -290,68 +290,68 @@  discard block
 block discarded – undo
290 290
     $index = 0;
291 291
     while ($index < count($diff)){
292 292
 
293
-      // determine the line type
294
-      switch ($diff[$index][1]){
293
+        // determine the line type
294
+        switch ($diff[$index][1]){
295 295
 
296 296
         // display the content on the left and right
297 297
         case self::UNMODIFIED:
298 298
           $leftCell =
299
-              self::getCellContent(
300
-                  $diff, $indentation, $separator, $index, self::UNMODIFIED);
301
-          $rightCell = $leftCell;
302
-          break;
299
+                self::getCellContent(
300
+                    $diff, $indentation, $separator, $index, self::UNMODIFIED);
301
+            $rightCell = $leftCell;
302
+            break;
303 303
 
304 304
         // display the deleted on the left and inserted content on the right
305 305
         case self::DELETED:
306 306
           $leftCell =
307
-              self::getCellContent(
308
-                  $diff, $indentation, $separator, $index, self::DELETED);
309
-          $rightCell =
310
-              self::getCellContent(
311
-                  $diff, $indentation, $separator, $index, self::INSERTED);
312
-          break;
307
+                self::getCellContent(
308
+                    $diff, $indentation, $separator, $index, self::DELETED);
309
+            $rightCell =
310
+                self::getCellContent(
311
+                    $diff, $indentation, $separator, $index, self::INSERTED);
312
+            break;
313 313
 
314 314
         // display the inserted content on the right
315 315
         case self::INSERTED:
316 316
           $leftCell = '';
317
-          $rightCell =
318
-              self::getCellContent(
319
-                  $diff, $indentation, $separator, $index, self::INSERTED);
320
-          break;
321
-
322
-      }
323
-
324
-      // extend the HTML with the new row
325
-      $html .=
326
-          $indentation
327
-          . "  <tr>\n"
328
-          . $indentation
329
-          . '    <td class="diff'
330
-          . ($leftCell == $rightCell
317
+            $rightCell =
318
+                self::getCellContent(
319
+                    $diff, $indentation, $separator, $index, self::INSERTED);
320
+            break;
321
+
322
+        }
323
+
324
+        // extend the HTML with the new row
325
+        $html .=
326
+            $indentation
327
+            . "  <tr>\n"
328
+            . $indentation
329
+            . '    <td class="diff'
330
+            . ($leftCell == $rightCell
331 331
               ? 'Unmodified'
332 332
               : ($leftCell == '' ? 'Blank' : 'Deleted'))
333
-          . '">'
334
-          . $leftCell
335
-          . "</td>\n"
336
-          . $indentation
337
-          . '    <td class="diff'
338
-          . ($leftCell == $rightCell
333
+            . '">'
334
+            . $leftCell
335
+            . "</td>\n"
336
+            . $indentation
337
+            . '    <td class="diff'
338
+            . ($leftCell == $rightCell
339 339
               ? 'Unmodified'
340 340
               : ($rightCell == '' ? 'Blank' : 'Inserted'))
341
-          . '">'
342
-          . $rightCell
343
-          . "</td>\n"
344
-          . $indentation
345
-          . "  </tr>\n";
341
+            . '">'
342
+            . $rightCell
343
+            . "</td>\n"
344
+            . $indentation
345
+            . "  </tr>\n";
346 346
 
347 347
     }
348 348
 
349 349
     // return the HTML
350 350
     return $html . $indentation . "</table>\n";
351 351
 
352
-  }
352
+    }
353 353
 
354
-  /* Returns the content of the cell, for use in the toTable function. The
354
+    /* Returns the content of the cell, for use in the toTable function. The
355 355
    * parameters are:
356 356
    *
357 357
    * $diff        - the diff array
@@ -360,25 +360,25 @@  discard block
 block discarded – undo
360 360
    * $index       - the current index, passes by reference
361 361
    * $type        - the type of line
362 362
    */
363
-  private static function getCellContent(
364
-      $diff, $indentation, $separator, &$index, $type){
363
+    private static function getCellContent(
364
+        $diff, $indentation, $separator, &$index, $type){
365 365
 
366 366
     // initialise the HTML
367 367
     $html = '';
368 368
 
369 369
     // loop over the matching lines, adding them to the HTML
370 370
     while ($index < count($diff) && $diff[$index][1] == $type){
371
-      $html .=
372
-          '<span>'
373
-          . htmlspecialchars($diff[$index][0])
374
-          . '</span>'
375
-          . $separator;
376
-      $index ++;
371
+        $html .=
372
+            '<span>'
373
+            . htmlspecialchars($diff[$index][0])
374
+            . '</span>'
375
+            . $separator;
376
+        $index ++;
377 377
     }
378 378
 
379 379
     // return the HTML
380 380
     return $html;
381 381
 
382
-  }
382
+    }
383 383
 
384 384
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 */
15 15
 
16 16
 // A class containing functions for computing diffs and formatting the output.
17
-class Diff{
17
+class Diff {
18 18
 
19 19
   // define the constants
20 20
   const UNMODIFIED = 0;
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
    *                      lines; this optional parameter defaults to false
35 35
    */
36 36
   public static function compare(
37
-      $string1, $string2, $compareCharacters = false){
37
+      $string1, $string2, $compareCharacters = false) {
38 38
 
39 39
     // initialise the sequences and comparison start and end positions
40 40
     $start = 0;
41
-    if ($compareCharacters){
41
+    if ($compareCharacters) {
42 42
       $sequence1 = $string1;
43 43
       $sequence2 = $string2;
44 44
       $end1 = strlen($string1) - 1;
45 45
       $end2 = strlen($string2) - 1;
46
-    }else{
46
+    } else {
47 47
       $sequence1 = preg_split('/\R/', $string1);
48 48
       $sequence2 = preg_split('/\R/', $string2);
49 49
       $end1 = count($sequence1) - 1;
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
 
53 53
     // skip any common prefix
54 54
     while ($start <= $end1 && $start <= $end2
55
-        && $sequence1[$start] == $sequence2[$start]){
56
-      $start ++;
55
+        && $sequence1[$start] == $sequence2[$start]) {
56
+      $start++;
57 57
     }
58 58
 
59 59
     // skip any common suffix
60 60
     while ($end1 >= $start && $end2 >= $start
61
-        && $sequence1[$end1] == $sequence2[$end2]){
62
-      $end1 --;
63
-      $end2 --;
61
+        && $sequence1[$end1] == $sequence2[$end2]) {
62
+      $end1--;
63
+      $end2--;
64 64
     }
65 65
 
66 66
     // compute the table of longest common subsequence lengths
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 
73 73
     // generate the full diff
74 74
     $diff = array();
75
-    for ($index = 0; $index < $start; $index ++){
75
+    for ($index = 0; $index < $start; $index++) {
76 76
       $diff[] = array($sequence1[$index], self::UNMODIFIED);
77 77
     }
78 78
     while (count($partialDiff) > 0) $diff[] = array_pop($partialDiff);
79 79
     for ($index = $end1 + 1;
80 80
         $index < ($compareCharacters ? strlen($sequence1) : count($sequence1));
81
-        $index ++){
81
+        $index++) {
82 82
       $diff[] = array($sequence1[$index], self::UNMODIFIED);
83 83
     }
84 84
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
    *                      lines; this optional parameter defaults to false
96 96
    */
97 97
   public static function compareFiles(
98
-      $file1, $file2, $compareCharacters = false){
98
+      $file1, $file2, $compareCharacters = false) {
99 99
 
100 100
     // return the diff of the files
101 101
     return self::compare(
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
    * $end2      - the ending index for the second sequence
116 116
    */
117 117
   private static function computeTable(
118
-      $sequence1, $sequence2, $start, $end1, $end2){
118
+      $sequence1, $sequence2, $start, $end1, $end2) {
119 119
 
120 120
     // determine the lengths to be compared
121 121
     $length1 = $end1 - $start + 1;
@@ -125,19 +125,19 @@  discard block
 block discarded – undo
125 125
     $table = array(array_fill(0, $length2 + 1, 0));
126 126
 
127 127
     // loop over the rows
128
-    for ($index1 = 1; $index1 <= $length1; $index1 ++){
128
+    for ($index1 = 1; $index1 <= $length1; $index1++) {
129 129
 
130 130
       // create the new row
131 131
       $table[$index1] = array(0);
132 132
 
133 133
       // loop over the columns
134
-      for ($index2 = 1; $index2 <= $length2; $index2 ++){
134
+      for ($index2 = 1; $index2 <= $length2; $index2++) {
135 135
 
136 136
         // store the longest common subsequence length
137 137
         if ($sequence1[$index1 + $start - 1]
138
-            == $sequence2[$index2 + $start - 1]){
138
+            == $sequence2[$index2 + $start - 1]) {
139 139
           $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1;
140
-        }else{
140
+        } else {
141 141
           $table[$index1][$index2] =
142 142
               max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]);
143 143
         }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
    * $start     - the starting index
160 160
    */
161 161
   private static function generatePartialDiff(
162
-      $table, $sequence1, $sequence2, $start){
162
+      $table, $sequence1, $sequence2, $start) {
163 163
 
164 164
     //  initialise the diff
165 165
     $diff = array();
@@ -169,30 +169,30 @@  discard block
 block discarded – undo
169 169
     $index2 = count($table[0]) - 1;
170 170
 
171 171
     // loop until there are no items remaining in either sequence
172
-    while ($index1 > 0 || $index2 > 0){
172
+    while ($index1 > 0 || $index2 > 0) {
173 173
 
174 174
       // check what has happened to the items at these indices
175 175
       if ($index1 > 0 && $index2 > 0
176 176
           && $sequence1[$index1 + $start - 1]
177
-              == $sequence2[$index2 + $start - 1]){
177
+              == $sequence2[$index2 + $start - 1]) {
178 178
 
179 179
         // update the diff and the indices
180 180
         $diff[] = array($sequence1[$index1 + $start - 1], self::UNMODIFIED);
181
-        $index1 --;
182
-        $index2 --;
181
+        $index1--;
182
+        $index2--;
183 183
 
184 184
       }elseif ($index2 > 0
185
-          && $table[$index1][$index2] == $table[$index1][$index2 - 1]){
185
+          && $table[$index1][$index2] == $table[$index1][$index2 - 1]) {
186 186
 
187 187
         // update the diff and the indices
188 188
         $diff[] = array($sequence2[$index2 + $start - 1], self::INSERTED);
189
-        $index2 --;
189
+        $index2--;
190 190
 
191
-      }else{
191
+      } else {
192 192
 
193 193
         // update the diff and the indices
194 194
         $diff[] = array($sequence1[$index1 + $start - 1], self::DELETED);
195
-        $index1 --;
195
+        $index1--;
196 196
 
197 197
       }
198 198
 
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
    * $separator - the separator between lines; this optional parameter defaults
212 212
    *              to "\n"
213 213
    */
214
-  public static function toString($diff, $separator = "\n"){
214
+  public static function toString($diff, $separator = "\n") {
215 215
 
216 216
     // initialise the string
217 217
     $string = '';
218 218
 
219 219
     // loop over the lines in the diff
220
-    foreach ($diff as $line){
220
+    foreach ($diff as $line) {
221 221
 
222 222
       // extend the string with the line
223
-      switch ($line[1]){
224
-        case self::UNMODIFIED : $string .= '  ' . $line[0];break;
225
-        case self::DELETED    : $string .= '- ' . $line[0];break;
226
-        case self::INSERTED   : $string .= '+ ' . $line[0];break;
223
+      switch ($line[1]) {
224
+        case self::UNMODIFIED : $string .= '  ' . $line[0]; break;
225
+        case self::DELETED    : $string .= '- ' . $line[0]; break;
226
+        case self::INSERTED   : $string .= '+ ' . $line[0]; break;
227 227
       }
228 228
 
229 229
       // extend the string with the separator
@@ -244,19 +244,19 @@  discard block
 block discarded – undo
244 244
    * $separator - the separator between lines; this optional parameter defaults
245 245
    *              to '<br>'
246 246
    */
247
-  public static function toHTML($diff, $separator = '<br>'){
247
+  public static function toHTML($diff, $separator = '<br>') {
248 248
 
249 249
     // initialise the HTML
250 250
     $html = '';
251 251
 
252 252
     // loop over the lines in the diff
253
-    foreach ($diff as $line){
253
+    foreach ($diff as $line) {
254 254
 
255 255
       // extend the HTML with the line
256
-      switch ($line[1]){
256
+      switch ($line[1]) {
257 257
         case self::UNMODIFIED : $element = 'span'; break;
258
-        case self::DELETED    : $element = 'del';  break;
259
-        case self::INSERTED   : $element = 'ins';  break;
258
+        case self::DELETED    : $element = 'del'; break;
259
+        case self::INSERTED   : $element = 'ins'; break;
260 260
       }
261 261
       $html .=
262 262
           '<' . $element . '>'
@@ -281,17 +281,17 @@  discard block
 block discarded – undo
281 281
    * $separator   - the separator between lines; this optional parameter
282 282
    *                defaults to '<br>'
283 283
    */
284
-  public static function toTable($diff, $indentation = '', $separator = '<br>'){
284
+  public static function toTable($diff, $indentation = '', $separator = '<br>') {
285 285
 
286 286
     // initialise the HTML
287 287
     $html = $indentation . "<table class=\"diff\">\n";
288 288
 
289 289
     // loop over the lines in the diff
290 290
     $index = 0;
291
-    while ($index < count($diff)){
291
+    while ($index < count($diff)) {
292 292
 
293 293
       // determine the line type
294
-      switch ($diff[$index][1]){
294
+      switch ($diff[$index][1]) {
295 295
 
296 296
         // display the content on the left and right
297 297
         case self::UNMODIFIED:
@@ -361,19 +361,19 @@  discard block
 block discarded – undo
361 361
    * $type        - the type of line
362 362
    */
363 363
   private static function getCellContent(
364
-      $diff, $indentation, $separator, &$index, $type){
364
+      $diff, $indentation, $separator, &$index, $type) {
365 365
 
366 366
     // initialise the HTML
367 367
     $html = '';
368 368
 
369 369
     // loop over the matching lines, adding them to the HTML
370
-    while ($index < count($diff) && $diff[$index][1] == $type){
370
+    while ($index < count($diff) && $diff[$index][1] == $type) {
371 371
       $html .=
372 372
           '<span>'
373 373
           . htmlspecialchars($diff[$index][0])
374 374
           . '</span>'
375 375
           . $separator;
376
-      $index ++;
376
+      $index++;
377 377
     }
378 378
 
379 379
     // return the HTML
Please login to merge, or discard this patch.
Braces   +7 added lines, -5 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
       $sequence2 = $string2;
44 44
       $end1 = strlen($string1) - 1;
45 45
       $end2 = strlen($string2) - 1;
46
-    }else{
46
+    } else{
47 47
       $sequence1 = preg_split('/\R/', $string1);
48 48
       $sequence2 = preg_split('/\R/', $string2);
49 49
       $end1 = count($sequence1) - 1;
@@ -75,7 +75,9 @@  discard block
 block discarded – undo
75 75
     for ($index = 0; $index < $start; $index ++){
76 76
       $diff[] = array($sequence1[$index], self::UNMODIFIED);
77 77
     }
78
-    while (count($partialDiff) > 0) $diff[] = array_pop($partialDiff);
78
+    while (count($partialDiff) > 0) {
79
+        $diff[] = array_pop($partialDiff);
80
+    }
79 81
     for ($index = $end1 + 1;
80 82
         $index < ($compareCharacters ? strlen($sequence1) : count($sequence1));
81 83
         $index ++){
@@ -137,7 +139,7 @@  discard block
 block discarded – undo
137 139
         if ($sequence1[$index1 + $start - 1]
138 140
             == $sequence2[$index2 + $start - 1]){
139 141
           $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1;
140
-        }else{
142
+        } else{
141 143
           $table[$index1][$index2] =
142 144
               max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]);
143 145
         }
@@ -181,14 +183,14 @@  discard block
 block discarded – undo
181 183
         $index1 --;
182 184
         $index2 --;
183 185
 
184
-      }elseif ($index2 > 0
186
+      } elseif ($index2 > 0
185 187
           && $table[$index1][$index2] == $table[$index1][$index2 - 1]){
186 188
 
187 189
         // update the diff and the indices
188 190
         $diff[] = array($sequence2[$index2 + $start - 1], self::INSERTED);
189 191
         $index2 --;
190 192
 
191
-      }else{
193
+      } else{
192 194
 
193 195
         // update the diff and the indices
194 196
         $diff[] = array($sequence1[$index1 + $start - 1], self::DELETED);
Please login to merge, or discard this patch.
app/filesystem/Filesystem.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@
 block discarded – undo
26 26
             $it = new \RecursiveDirectoryIterator($filename_clean, \RecursiveDirectoryIterator::SKIP_DOTS);
27 27
             $files = new \RecursiveIteratorIterator($it,
28 28
                         \RecursiveIteratorIterator::CHILD_FIRST);
29
-            foreach($files as $file) {
30
-                if ($file->isDir()){
29
+            foreach ($files as $file) {
30
+                if ($file->isDir()) {
31 31
                     rmdir($file->getRealPath());
32 32
                 } else {
33 33
                     unlink($file->getRealPath());
Please login to merge, or discard this patch.
app/generators/Language/LanguageGenerator.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -181,13 +181,13 @@
 block discarded – undo
181 181
 "Country-Code: ${country-code}\n"
182 182
 EOD;
183 183
 
184
-        $language_code          = $this->config->getOr('language', 'addon.default_language');
184
+        $language_code = $this->config->getOr('language', 'addon.default_language');
185 185
 
186 186
         if (!$language_code) {
187 187
             throw new \InvalidArgumentException('Nor language param and addon default_language are specified');
188 188
         }
189 189
 
190
-        $language_information   = self::$codes[$language_code];
190
+        $language_information = self::$codes[$language_code];
191 191
         $po_heading = str_replace(
192 192
             [
193 193
                 '${code}',
Please login to merge, or discard this patch.
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@
 block discarded – undo
7 7
 use mediators\AbstractMediator;
8 8
 
9 9
 /**
10
-  * @property string FILENAME
11
-  * @property string $templatePath
12
-  * @property string $recycleBin - buffer to which be removed all langvars from actual content
13
-  * @property string $content
14
-  * @property Config $config
15
-  * @property AbstractMediator $mediator
16
-  * @property array $codes
17
-  * @property string $eol - end of line char
18
-  * @todo add all $codes supported by cs-cart
19
-  */
10
+ * @property string FILENAME
11
+ * @property string $templatePath
12
+ * @property string $recycleBin - buffer to which be removed all langvars from actual content
13
+ * @property string $content
14
+ * @property Config $config
15
+ * @property AbstractMediator $mediator
16
+ * @property array $codes
17
+ * @property string $eol - end of line char
18
+ * @todo add all $codes supported by cs-cart
19
+ */
20 20
 final class LanguageGenerator extends \generators\AbstractGenerator
21 21
 {
22 22
     const FILENAME = 'var/langs/${lang}/addons/${addon}.po';
Please login to merge, or discard this patch.
app/generators/AddonXml/AddonXmlGenerator.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -352,7 +352,7 @@
 block discarded – undo
352 352
             $settingItem->addChild('type', $type);
353 353
             if ($variants) {
354 354
                 $variantsElement = $settingItem->addChild('variants');
355
-                    foreach($variants as $variant)
355
+                    foreach ($variants as $variant)
356 356
                     {
357 357
                         $variantElement = $variantsElement->addChild('item');
358 358
                             $variantElement->addAttribute('id', $variant);
Please login to merge, or discard this patch.
app/mediators/GeneratorMediator.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function addGenerator(AbstractGenerator $generator)
19 19
     {
20
-        switch(get_class($generator))
20
+        switch (get_class($generator))
21 21
         {
22 22
             case 'generators\AddonXml\AddonXmlGenerator':
23 23
                 $this->addonXmlGenerator = $generator;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                     );
108 108
 
109 109
                 if (!empty($data['variants'])) {
110
-                    foreach($data['variants'] as $variation) {
110
+                    foreach ($data['variants'] as $variation) {
111 111
                         $this->languageGenerator
112 112
                             ->replaceLangvar(
113 113
                                 LanguageGenerator::getTranslationKey(
Please login to merge, or discard this patch.
app/helpers/string.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
             $key = $matches[1];
55 55
             $value = true;
56 56
 
57
-            switch(count($matches)) {
57
+            switch (count($matches)) {
58 58
                 case 4:
59 59
                 case 5:
60 60
                     $value = $matches[3];
Please login to merge, or discard this patch.
app/helpers/file.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@
 block discarded – undo
9 9
         if (
10 10
             ($prefix = substr($input, 0, 3)) == '../' ||
11 11
             ($prefix = substr($input, 0, 2)) == './'
12
-           ) {
12
+            ) {
13 13
             $input = substr($input, strlen($prefix));
14 14
         } else if (
15 15
             ($prefix = substr($input, 0, 3)) == '/./' ||
16 16
             ($prefix = $input) == '/.'
17
-           ) {
17
+            ) {
18 18
             $input = '/' . substr($input, strlen($prefix));
19 19
         } else
20 20
 
21 21
         if (
22 22
             ($prefix = substr($input, 0, 4)) == '/../' ||
23 23
             ($prefix = $input) == '/..'
24
-           ) {
24
+            ) {
25 25
             $input = '/' . substr($input, strlen($prefix));
26 26
             $output = substr($output, 0, strrpos($output, '/'));
27 27
         } else if ($input == '.' || $input == '..') {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
             $input = '';
29 29
         } else {
30 30
             $pos = strpos($input, '/');
31
-            if ($pos === 0) $pos = strpos($input, '/', $pos+1);
31
+            if ($pos === 0) $pos = strpos($input, '/', $pos + 1);
32 32
             if ($pos === false) $pos = strlen($input);
33 33
             $output .= substr($input, 0, $pos);
34 34
             $input = (string) substr($input, $pos);
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,8 +28,12 @@
 block discarded – undo
28 28
             $input = '';
29 29
         } else {
30 30
             $pos = strpos($input, '/');
31
-            if ($pos === 0) $pos = strpos($input, '/', $pos+1);
32
-            if ($pos === false) $pos = strlen($input);
31
+            if ($pos === 0) {
32
+                $pos = strpos($input, '/', $pos+1);
33
+            }
34
+            if ($pos === false) {
35
+                $pos = strlen($input);
36
+            }
33 37
             $output .= substr($input, 0, $pos);
34 38
             $input = (string) substr($input, $pos);
35 39
         }
Please login to merge, or discard this patch.
ccg.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,9 +10,9 @@
 block discarded – undo
10 10
 /**
11 11
  * autoload
12 12
  */
13
-spl_autoload_register(function ($class) {
13
+spl_autoload_register(function($class) {
14 14
     $file = realpath(__DIR__ . '/' . 'app') . '/' . str_replace('\\', '/', $class) . '.php';
15
-    if(file_exists($file)) {
15
+    if (file_exists($file)) {
16 16
         require_once($file);
17 17
     }
18 18
 });
Please login to merge, or discard this patch.
app/controllers/AddonXml.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -228,7 +228,7 @@
 block discarded – undo
228 228
 
229 229
     public function setSettingsItemAutocomplete()
230 230
     {
231
-        $generator      = $this->mfGenerator
231
+        $generator = $this->mfGenerator
232 232
             ->find(AddonXmlGenerator::class)
233 233
                 ->extract();
234 234
 
Please login to merge, or discard this patch.