Passed
Push — master ( cb3f3d...9869d4 )
by Sebastian
08:22
created
src/Diff/Styler.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
         $folder = sprintf(__DIR__.'/../../css/%s', $this->fileName);
42 42
         $path = realpath($folder);
43 43
         
44
-        if($path === false)
44
+        if ($path === false)
45 45
         {
46 46
             throw new DiffException(
47 47
                 'Could not find the highlight CSS file',
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -79,23 +79,23 @@
 block discarded – undo
79 79
         );
80 80
     }
81 81
     
82
-   /**
83
-    * Retrieves the path to the stylesheet file.
84
-    * 
85
-    * @return string
86
-    */
82
+    /**
83
+     * Retrieves the path to the stylesheet file.
84
+     * 
85
+     * @return string
86
+     */
87 87
     public function getStylesheetPath() : string
88 88
     {
89 89
         return $this->path;
90 90
     }
91 91
     
92
-   /**
93
-    * Retrieves the URL to the stylesheet file, given the
94
-    * local URL to the application's vendor folder.
95
-    *  
96
-    * @param string $vendorURL The URL to the vendor folder (must be accessible in the webroot).
97
-    * @return string
98
-    */
92
+    /**
93
+     * Retrieves the URL to the stylesheet file, given the
94
+     * local URL to the application's vendor folder.
95
+     *  
96
+     * @param string $vendorURL The URL to the vendor folder (must be accessible in the webroot).
97
+     * @return string
98
+     */
99 99
     public function getStylesheetURL(string $vendorURL) : string
100 100
     {
101 101
         return sprintf(
Please login to merge, or discard this patch.
src/Diff/Renderer/PlainText.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@
 block discarded – undo
36 36
             // extend the string with the line
37 37
             switch ($line[1])
38 38
             {
39
-                case Diff::UNMODIFIED : $string .= '  ' . $line[0];break;
40
-                case Diff::DELETED    : $string .= '- ' . $line[0];break;
41
-                case Diff::INSERTED   : $string .= '+ ' . $line[0];break;
39
+                case Diff::UNMODIFIED : $string .= '  '.$line[0]; break;
40
+                case Diff::DELETED    : $string .= '- '.$line[0]; break;
41
+                case Diff::INSERTED   : $string .= '+ '.$line[0]; break;
42 42
             }
43 43
             
44 44
             // extend the string with the separator
Please login to merge, or discard this patch.
src/Diff/Renderer/HTMLTable.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
15 15
     private string $nl = PHP_EOL;
16 16
     private string $container = '<table class="text-diff-container">%s</table>';
17 17
 
18
-   /**
19
-    * @var array<int, array<int,int|string>>
20
-    */
18
+    /**
19
+     * @var array<int, array<int,int|string>>
20
+     */
21 21
     private $array;
22 22
 
23
-   /**
24
-    * Sets the tab character(s) to indent the HTML code with.
25
-    * This is used to indent the table's tags beyond the
26
-    * base indentation.
27
-    * 
28
-    * @param string $tab
29
-    * @return HTMLTable
30
-    * @see HTMLTable::setIndentation()
31
-    */
23
+    /**
24
+     * Sets the tab character(s) to indent the HTML code with.
25
+     * This is used to indent the table's tags beyond the
26
+     * base indentation.
27
+     * 
28
+     * @param string $tab
29
+     * @return HTMLTable
30
+     * @see HTMLTable::setIndentation()
31
+     */
32 32
     public function setTab(string $tab) : HTMLTable
33 33
     {
34 34
         $this->tab = $tab;
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
         return $this->nl;
47 47
     }
48 48
     
49
-   /**
50
-    * Sets the character
51
-    * @param string $separator
52
-    * @return HTMLTable
53
-    */
49
+    /**
50
+     * Sets the character
51
+     * @param string $separator
52
+     * @return HTMLTable
53
+     */
54 54
     public function setSeparator(string $separator) : HTMLTable
55 55
     {
56 56
         $this->separator = $separator;
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
         return $this;
59 59
     }
60 60
     
61
-   /**
62
-    * Sets the character(s) to indent the whole table with.
63
-    *  
64
-    * @param string $indent
65
-    * @return HTMLTable
66
-    * @see HTMLTable::setTab()
67
-    */
61
+    /**
62
+     * Sets the character(s) to indent the whole table with.
63
+     *  
64
+     * @param string $indent
65
+     * @return HTMLTable
66
+     * @see HTMLTable::setTab()
67
+     */
68 68
     public function setIndentation(string $indent) : HTMLTable
69 69
     {
70 70
         $this->indentation = $indent;
@@ -173,13 +173,13 @@  discard block
 block discarded – undo
173 173
         return 'unmodified';
174 174
     }
175 175
     
176
-   /**
177
-    * Returns the content of the cell.
178
-    * 
179
-    * @param int $index
180
-    * @param int $type The operation type (inset/delete/unmodified)
181
-    * @return string
182
-    */
176
+    /**
177
+     * Returns the content of the cell.
178
+     * 
179
+     * @param int $index
180
+     * @param int $type The operation type (inset/delete/unmodified)
181
+     * @return string
182
+     */
183 183
     private function getCellContent(int &$index, int $type) : string
184 184
     {
185 185
         // initialise the HTML
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -133,24 +133,24 @@  discard block
 block discarded – undo
133 133
             
134 134
             // extend the HTML with the new row
135 135
             $html .=
136
-            $i2. "<tr>". $nl . 
137
-            $i3.     '<td class="text-diff-'.$leftType. '">'. $leftCell . "</td>".$nl.
138
-            $i3.     '<td class="text-diff-'.$rightType. '">'. $rightCell . "</td>".$nl.
139
-            $i2. "</tr>".$nl;
136
+            $i2."<tr>".$nl. 
137
+            $i3.'<td class="text-diff-'.$leftType.'">'.$leftCell."</td>".$nl.
138
+            $i3.'<td class="text-diff-'.$rightType.'">'.$rightCell."</td>".$nl.
139
+            $i2."</tr>".$nl;
140 140
                                                 
141 141
         }
142 142
         
143
-        return $i1. sprintf($this->container, $nl.$html).$nl;
143
+        return $i1.sprintf($this->container, $nl.$html).$nl;
144 144
     }
145 145
     
146 146
     private function resolveLeftType(string $leftCell, string $rightCell) : string
147 147
     {
148
-        if(empty($leftCell))
148
+        if (empty($leftCell))
149 149
         {
150 150
             return 'empty';
151 151
         }
152 152
         
153
-        if($leftCell !== $rightCell)
153
+        if ($leftCell !== $rightCell)
154 154
         {
155 155
             return 'del';
156 156
         }
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
     
161 161
     private function resolveRightType(string $leftCell, string $rightCell) : string
162 162
     {
163
-        if(empty($rightCell))
163
+        if (empty($rightCell))
164 164
         {
165 165
             return 'empty';
166 166
         }
167 167
         
168
-        if($leftCell !== $rightCell)
168
+        if ($leftCell !== $rightCell)
169 169
         {
170 170
             return 'ins';
171 171
         }
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
             $html .= sprintf(
193 193
                 '<%1$s>%2$s</%1$s>%3$s',
194 194
                 $tag,
195
-                htmlspecialchars((string)$this->array[$index][0]),
195
+                htmlspecialchars((string) $this->array[$index][0]),
196 196
                 $this->separator
197 197
             );
198 198
             
199
-            $index ++;
199
+            $index++;
200 200
         }
201 201
         
202 202
         return $html;
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
     
205 205
     private function resolveTag(int $type) : string
206 206
     {
207
-        switch($type)
207
+        switch ($type)
208 208
         {
209 209
             case Diff::DELETED: return 'del';
210 210
             case Diff::INSERTED: return 'ins';
Please login to merge, or discard this patch.
src/Diff/Renderer/HTML.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,14 +48,14 @@
 block discarded – undo
48 48
             switch ($line[1])
49 49
             {
50 50
                 case Diff::UNMODIFIED : $element = 'span'; break;
51
-                case Diff::DELETED    : $element = 'del';  break;
52
-                case Diff::INSERTED   : $element = 'ins';  break;
51
+                case Diff::DELETED    : $element = 'del'; break;
52
+                case Diff::INSERTED   : $element = 'ins'; break;
53 53
             }
54 54
             
55 55
             $html .= sprintf(
56 56
                 '<%1$s>%2$s</%1$s>',
57 57
                 $element,
58
-                htmlspecialchars((string)$line[0])
58
+                htmlspecialchars((string) $line[0])
59 59
             );
60 60
             
61 61
             // extend the HTML with the separator
Please login to merge, or discard this patch.
src/Diff/Renderer.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@
 block discarded – undo
15 15
         $this->diff = $diff;
16 16
     }
17 17
     
18
-   /**
19
-    * @return mixed
20
-    */
18
+    /**
19
+     * @return mixed
20
+     */
21 21
     abstract public function render();
22 22
 }
Please login to merge, or discard this patch.
src/Diff.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
     private string $string2;
43 43
     private bool $disposed = false;
44 44
 
45
-   /**
46
-    * @var string|string[]
47
-    */
45
+    /**
46
+     * @var string|string[]
47
+     */
48 48
     private $sequence1 = '';
49 49
     
50
-   /**
51
-    * @var string|string[]
52
-    */
50
+    /**
51
+     * @var string|string[]
52
+     */
53 53
     private $sequence2 = '';
54 54
     
55 55
     public function __construct(string $string1, string $string2)
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
         $this->string2 = $string2;
59 59
     }
60 60
     
61
-   /**
62
-    * Sets whether to compare single characters. Default is to 
63
-    * compare only lines.
64
-    * 
65
-    * @param bool $compare
66
-    * @return Diff
67
-    */
61
+    /**
62
+     * Sets whether to compare single characters. Default is to 
63
+     * compare only lines.
64
+     * 
65
+     * @param bool $compare
66
+     * @return Diff
67
+     */
68 68
     public function setCompareCharacters(bool $compare=true) : Diff
69 69
     {
70 70
         $this->compareCharacters = $compare;
@@ -72,19 +72,19 @@  discard block
 block discarded – undo
72 72
         return $this;
73 73
     }
74 74
     
75
-   /**
76
-    * Returns the diff for two strings. The return value is an array, each of
77
-    * whose values are an array containing two values: a line (or character, if
78
-    * $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the
79
-    * line or character is in both strings), DIFF::DELETED (the line or character
80
-    * is only in the first string), and DIFF::INSERTED (the line or character is
81
-    * only in the second string).
82
-    * 
83
-    * @param string $string1
84
-    * @param string $string2
85
-    * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise)
86
-    * @return Diff
87
-    */
75
+    /**
76
+     * Returns the diff for two strings. The return value is an array, each of
77
+     * whose values are an array containing two values: a line (or character, if
78
+     * $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the
79
+     * line or character is in both strings), DIFF::DELETED (the line or character
80
+     * is only in the first string), and DIFF::INSERTED (the line or character is
81
+     * only in the second string).
82
+     * 
83
+     * @param string $string1
84
+     * @param string $string2
85
+     * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise)
86
+     * @return Diff
87
+     */
88 88
     public static function compareStrings(string $string1, string $string2, bool $compareCharacters = false) : Diff
89 89
     {
90 90
         $diff = new Diff($string1, $string2);
@@ -92,16 +92,16 @@  discard block
 block discarded – undo
92 92
         return $diff;
93 93
     }
94 94
     
95
-   /**
96
-    * Like {@see Diff::compare()}, but returns the diff for two files.
97
-    *
98
-    * @param string $file1
99
-    * @param string $file2
100
-    * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise)
101
-    * @return Diff
102
-    *
103
-    * @throws FileHelper_Exception If one of the files cannot be found or opened.
104
-    */
95
+    /**
96
+     * Like {@see Diff::compare()}, but returns the diff for two files.
97
+     *
98
+     * @param string $file1
99
+     * @param string $file2
100
+     * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise)
101
+     * @return Diff
102
+     *
103
+     * @throws FileHelper_Exception If one of the files cannot be found or opened.
104
+     */
105 105
     public static function compareFiles(string $file1, string $file2, bool $compareCharacters = false) : Diff
106 106
     {
107 107
         return self::compareStrings(
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
         );
112 112
     }
113 113
     
114
-   /**
115
-    * Creates an instance of the styler class, which
116
-    * is used to access the CSS used for the syntax
117
-    * highlighting in the HTML renderers.
118
-    * 
119
-    * @return Styler
120
-    */
114
+    /**
115
+     * Creates an instance of the styler class, which
116
+     * is used to access the CSS used for the syntax
117
+     * highlighting in the HTML renderers.
118
+     * 
119
+     * @return Styler
120
+     */
121 121
     public static function createStyler() : Styler
122 122
     {
123 123
         return new Styler();
@@ -225,13 +225,13 @@  discard block
 block discarded – undo
225 225
         return $diff;
226 226
     }
227 227
     
228
-   /**
229
-    * Splits the string into individual lines.
230
-    * 
231
-    * @param string $string
232
-    * @throws DiffException
233
-    * @return string[]
234
-    */
228
+    /**
229
+     * Splits the string into individual lines.
230
+     * 
231
+     * @param string $string
232
+     * @throws DiffException
233
+     * @return string[]
234
+     */
235 235
     public static function splitLines(string $string) : array
236 236
     {
237 237
         $split = preg_split('/\R/u', $string);
@@ -271,15 +271,15 @@  discard block
 block discarded – undo
271 271
         );
272 272
     }
273 273
     
274
-   /**
275
-    * Returns the table of the longest common subsequence lengths
276
-    * for the specified sequences.
277
-    * 
278
-    * @param int $start
279
-    * @param int $end1
280
-    * @param int $end2
281
-    * @return array<int,array<int,int>>
282
-    */
274
+    /**
275
+     * Returns the table of the longest common subsequence lengths
276
+     * for the specified sequences.
277
+     * 
278
+     * @param int $start
279
+     * @param int $end1
280
+     * @param int $end2
281
+     * @return array<int,array<int,int>>
282
+     */
283 283
     private function computeTable(int $start, int $end1, int $end2) : array
284 284
     {
285 285
         // determine the lengths to be compared
@@ -313,14 +313,14 @@  discard block
 block discarded – undo
313 313
         return $table;
314 314
     }
315 315
     
316
-   /**
317
-    * Returns the partial diff for the specified sequences, in reverse order.
318
-    * 
319
-    * @param int $start
320
-    * @param int $end1
321
-    * @param int $end2
322
-    * @return array<int,array<int,int|string>>
323
-    */
316
+    /**
317
+     * Returns the partial diff for the specified sequences, in reverse order.
318
+     * 
319
+     * @param int $start
320
+     * @param int $end1
321
+     * @param int $end2
322
+     * @return array<int,array<int,int|string>>
323
+     */
324 324
     private function generatePartialDiff(int $start, int $end1, int $end2) : array
325 325
     {
326 326
         // compute the table of the longest common subsequence lengths
@@ -367,13 +367,13 @@  discard block
 block discarded – undo
367 367
         return $diff;
368 368
     }
369 369
     
370
-   /**
371
-    * Returns a diff as a string, where unmodified lines are prefixed by '  ',
372
-    * deletions are prefixed by '- ', and insertions are prefixed by '+ '.
373
-    * 
374
-    * @param string $separator
375
-    * @return string
376
-    */
370
+    /**
371
+     * Returns a diff as a string, where unmodified lines are prefixed by '  ',
372
+     * deletions are prefixed by '- ', and insertions are prefixed by '+ '.
373
+     * 
374
+     * @param string $separator
375
+     * @return string
376
+     */
377 377
     public function toString(string $separator = "\n") : string
378 378
     {
379 379
         $renderer = new PlainText($this);
@@ -382,14 +382,14 @@  discard block
 block discarded – undo
382 382
         return $renderer->render();
383 383
     }
384 384
     
385
-   /**
386
-    * Returns a diff as an HTML string, where unmodified lines are contained
387
-    * within 'span' elements, deletions are contained within 'del' elements, and
388
-    * insertions are contained within 'ins' elements.
389
-    * 
390
-    * @param string $separator
391
-    * @return string
392
-    */
385
+    /**
386
+     * Returns a diff as an HTML string, where unmodified lines are contained
387
+     * within 'span' elements, deletions are contained within 'del' elements, and
388
+     * insertions are contained within 'ins' elements.
389
+     * 
390
+     * @param string $separator
391
+     * @return string
392
+     */
393 393
     public function toHTML(string $separator = '<br>') : string
394 394
     {
395 395
         $renderer = new HTML($this);
@@ -398,13 +398,13 @@  discard block
 block discarded – undo
398 398
         return $renderer->render();
399 399
     }
400 400
     
401
-   /**
402
-    * Returns a diff as an HTML table.
403
-    * 
404
-    * @param string $indentation
405
-    * @param string $separator
406
-    * @return string
407
-    */
401
+    /**
402
+     * Returns a diff as an HTML table.
403
+     * 
404
+     * @param string $indentation
405
+     * @param string $separator
406
+     * @return string
407
+     */
408 408
     public function toHTMLTable(string $indentation = '', string $separator = '<br>') : string
409 409
     {
410 410
         $renderer = new HTMLTable($this);
@@ -414,12 +414,12 @@  discard block
 block discarded – undo
414 414
         return $renderer->render();
415 415
     }
416 416
     
417
-   /**
418
-    * Disposes of the diff by clearing the stored strings,
419
-    * to free memory until the class is destructed.
420
-    * 
421
-    * @return Diff
422
-    */
417
+    /**
418
+     * Disposes of the diff by clearing the stored strings,
419
+     * to free memory until the class is destructed.
420
+     * 
421
+     * @return Diff
422
+     */
423 423
     public function dispose() : Diff
424 424
     {
425 425
         $this->string1 = '';
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     * @param bool $compare
66 66
     * @return Diff
67 67
     */
68
-    public function setCompareCharacters(bool $compare=true) : Diff
68
+    public function setCompareCharacters(bool $compare = true) : Diff
69 69
     {
70 70
         $this->compareCharacters = $compare;
71 71
         
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      */
158 158
     public function toArray() : array
159 159
     {
160
-        if($this->disposed)
160
+        if ($this->disposed)
161 161
         {
162 162
             throw new DiffException(
163 163
                 'The diff has been disposed.',
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
         // skip any common prefix
188 188
         while ($start <= $end1 && $start <= $end2 && $this->sequence1[$start] === $this->sequence2[$start])
189 189
         {
190
-            $start ++;
190
+            $start++;
191 191
         }
192 192
         
193 193
         // skip any common suffix
194 194
         while ($end1 >= $start && $end2 >= $start && $this->sequence1[$end1] === $this->sequence2[$end2])
195 195
         {
196
-            $end1 --;
197
-            $end2 --;
196
+            $end1--;
197
+            $end2--;
198 198
         }
199 199
         
200 200
         // generate the partial diff
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
         // generate the full diff
204 204
         $diff = array();
205 205
         
206
-        for ($index = 0; $index < $start; $index ++)
206
+        for ($index = 0; $index < $start; $index++)
207 207
         {
208 208
             $diff[] = array($this->sequence1[$index], self::UNMODIFIED);
209 209
         }
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             $diff[] = array_pop($partialDiff);
214 214
         }
215 215
         
216
-        for ($index = $end1 + 1; $index < $totalSequence; $index ++)
216
+        for ($index = $end1 + 1; $index < $totalSequence; $index++)
217 217
         {
218 218
             $diff[] = array($this->sequence1[$index], self::UNMODIFIED);
219 219
         }
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
     {
237 237
         $split = preg_split('/\R/u', $string);
238 238
         
239
-        if(is_array($split))
239
+        if (is_array($split))
240 240
         {
241 241
             return $split;
242 242
         }
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
     {
260 260
         $split = mb_str_split($string);
261 261
 
262
-        if(is_array($split))
262
+        if (is_array($split))
263 263
         {
264 264
             return $split;
265 265
         }
@@ -290,19 +290,19 @@  discard block
 block discarded – undo
290 290
         $table = array(array_fill(0, $length2 + 1, 0));
291 291
         
292 292
         // loop over the rows
293
-        for ($index1 = 1; $index1 <= $length1; $index1 ++){
293
+        for ($index1 = 1; $index1 <= $length1; $index1++) {
294 294
             
295 295
             // create the new row
296 296
             $table[$index1] = array(0);
297 297
             
298 298
             // loop over the columns
299
-            for ($index2 = 1; $index2 <= $length2; $index2 ++){
299
+            for ($index2 = 1; $index2 <= $length2; $index2++) {
300 300
                 
301 301
                 // store the longest common subsequence length
302 302
                 if ($this->sequence1[$index1 + $start - 1]
303
-                    === $this->sequence2[$index2 + $start - 1]){
303
+                    === $this->sequence2[$index2 + $start - 1]) {
304 304
                         $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1;
305
-                }else{
305
+                } else {
306 306
                     $table[$index1][$index2] =
307 307
                     max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]);
308 308
                 }
@@ -341,11 +341,11 @@  discard block
 block discarded – undo
341 341
                 $index1 > 0 && $index2 > 0
342 342
                 && $this->sequence1[$index1 + $start - 1]
343 343
                 === $this->sequence2[$index2 + $start - 1]
344
-            ){
344
+            ) {
345 345
                 // update the diff and the indices
346 346
                 $diff[] = array($this->sequence1[$index1 + $start - 1], self::UNMODIFIED);
347
-                $index1 --;
348
-                $index2 --;
347
+                $index1--;
348
+                $index2--;
349 349
             }
350 350
             elseif (
351 351
                 $index2 > 0
@@ -353,13 +353,13 @@  discard block
 block discarded – undo
353 353
             ) {
354 354
                 // update the diff and the indices
355 355
                 $diff[] = array($this->sequence2[$index2 + $start - 1], self::INSERTED);
356
-                $index2 --;
356
+                $index2--;
357 357
             }
358 358
             else
359 359
             {
360 360
                 // update the diff and the indices
361 361
                 $diff[] = array($this->sequence1[$index1 + $start - 1], self::DELETED);
362
-                $index1 --;
362
+                $index1--;
363 363
             }
364 364
         }
365 365
         
Please login to merge, or discard this patch.