@@ -42,14 +42,14 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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(); |
@@ -227,13 +227,13 @@ discard block |
||
227 | 227 | return $diff; |
228 | 228 | } |
229 | 229 | |
230 | - /** |
|
231 | - * Splits the string into individual characters. |
|
232 | - * |
|
233 | - * @param string $string |
|
234 | - * @throws DiffException |
|
235 | - * @return string[] |
|
236 | - */ |
|
230 | + /** |
|
231 | + * Splits the string into individual characters. |
|
232 | + * |
|
233 | + * @param string $string |
|
234 | + * @throws DiffException |
|
235 | + * @return string[] |
|
236 | + */ |
|
237 | 237 | private function splitString(string $string) : array |
238 | 238 | { |
239 | 239 | $split = preg_split('/\R/', $string); |
@@ -250,15 +250,15 @@ discard block |
||
250 | 250 | ); |
251 | 251 | } |
252 | 252 | |
253 | - /** |
|
254 | - * Returns the table of the longest common subsequence lengths |
|
255 | - * for the specified sequences. |
|
256 | - * |
|
257 | - * @param int $start |
|
258 | - * @param int $end1 |
|
259 | - * @param int $end2 |
|
260 | - * @return array<int,array<int,int>> |
|
261 | - */ |
|
253 | + /** |
|
254 | + * Returns the table of the longest common subsequence lengths |
|
255 | + * for the specified sequences. |
|
256 | + * |
|
257 | + * @param int $start |
|
258 | + * @param int $end1 |
|
259 | + * @param int $end2 |
|
260 | + * @return array<int,array<int,int>> |
|
261 | + */ |
|
262 | 262 | private function computeTable(int $start, int $end1, int $end2) : array |
263 | 263 | { |
264 | 264 | // determine the lengths to be compared |
@@ -292,14 +292,14 @@ discard block |
||
292 | 292 | return $table; |
293 | 293 | } |
294 | 294 | |
295 | - /** |
|
296 | - * Returns the partial diff for the specified sequences, in reverse order. |
|
297 | - * |
|
298 | - * @param int $start |
|
299 | - * @param int $end1 |
|
300 | - * @param int $end2 |
|
301 | - * @return array<int,array<int,int|string>> |
|
302 | - */ |
|
295 | + /** |
|
296 | + * Returns the partial diff for the specified sequences, in reverse order. |
|
297 | + * |
|
298 | + * @param int $start |
|
299 | + * @param int $end1 |
|
300 | + * @param int $end2 |
|
301 | + * @return array<int,array<int,int|string>> |
|
302 | + */ |
|
303 | 303 | private function generatePartialDiff(int $start, int $end1, int $end2) : array |
304 | 304 | { |
305 | 305 | // compute the table of the longest common subsequence lengths |
@@ -346,13 +346,13 @@ discard block |
||
346 | 346 | return $diff; |
347 | 347 | } |
348 | 348 | |
349 | - /** |
|
350 | - * Returns a diff as a string, where unmodified lines are prefixed by ' ', |
|
351 | - * deletions are prefixed by '- ', and insertions are prefixed by '+ '. |
|
352 | - * |
|
353 | - * @param string $separator |
|
354 | - * @return string |
|
355 | - */ |
|
349 | + /** |
|
350 | + * Returns a diff as a string, where unmodified lines are prefixed by ' ', |
|
351 | + * deletions are prefixed by '- ', and insertions are prefixed by '+ '. |
|
352 | + * |
|
353 | + * @param string $separator |
|
354 | + * @return string |
|
355 | + */ |
|
356 | 356 | public function toString(string $separator = "\n") : string |
357 | 357 | { |
358 | 358 | $renderer = new PlainText($this); |
@@ -361,14 +361,14 @@ discard block |
||
361 | 361 | return $renderer->render(); |
362 | 362 | } |
363 | 363 | |
364 | - /** |
|
365 | - * Returns a diff as an HTML string, where unmodified lines are contained |
|
366 | - * within 'span' elements, deletions are contained within 'del' elements, and |
|
367 | - * insertions are contained within 'ins' elements. |
|
368 | - * |
|
369 | - * @param string $separator |
|
370 | - * @return string |
|
371 | - */ |
|
364 | + /** |
|
365 | + * Returns a diff as an HTML string, where unmodified lines are contained |
|
366 | + * within 'span' elements, deletions are contained within 'del' elements, and |
|
367 | + * insertions are contained within 'ins' elements. |
|
368 | + * |
|
369 | + * @param string $separator |
|
370 | + * @return string |
|
371 | + */ |
|
372 | 372 | public function toHTML(string $separator = '<br>') : string |
373 | 373 | { |
374 | 374 | $renderer = new HTML($this); |
@@ -377,13 +377,13 @@ discard block |
||
377 | 377 | return $renderer->render(); |
378 | 378 | } |
379 | 379 | |
380 | - /** |
|
381 | - * Returns a diff as an HTML table. |
|
382 | - * |
|
383 | - * @param string $indentation |
|
384 | - * @param string $separator |
|
385 | - * @return string |
|
386 | - */ |
|
380 | + /** |
|
381 | + * Returns a diff as an HTML table. |
|
382 | + * |
|
383 | + * @param string $indentation |
|
384 | + * @param string $separator |
|
385 | + * @return string |
|
386 | + */ |
|
387 | 387 | public function toHTMLTable(string $indentation = '', string $separator = '<br>') : string |
388 | 388 | { |
389 | 389 | $renderer = new HTMLTable($this); |
@@ -393,12 +393,12 @@ discard block |
||
393 | 393 | return $renderer->render(); |
394 | 394 | } |
395 | 395 | |
396 | - /** |
|
397 | - * Disposes of the diff by clearing the stored strings, |
|
398 | - * to free memory until the class is destructed. |
|
399 | - * |
|
400 | - * @return Diff |
|
401 | - */ |
|
396 | + /** |
|
397 | + * Disposes of the diff by clearing the stored strings, |
|
398 | + * to free memory until the class is destructed. |
|
399 | + * |
|
400 | + * @return Diff |
|
401 | + */ |
|
402 | 402 | public function dispose() : Diff |
403 | 403 | { |
404 | 404 | $this->string1 = ''; |
@@ -176,8 +176,7 @@ discard block |
||
176 | 176 | $end1 = strlen($this->string1) - 1; |
177 | 177 | $end2 = strlen($this->string2) - 1; |
178 | 178 | $totalSequence = strlen($this->sequence1); |
179 | - } |
|
180 | - else |
|
179 | + } else |
|
181 | 180 | { |
182 | 181 | $this->sequence1 = $this->splitString($this->string1); |
183 | 182 | $this->sequence2 = $this->splitString($this->string2); |
@@ -281,7 +280,7 @@ discard block |
||
281 | 280 | if ($this->sequence1[$index1 + $start - 1] |
282 | 281 | === $this->sequence2[$index2 + $start - 1]){ |
283 | 282 | $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1; |
284 | - }else{ |
|
283 | + } else{ |
|
285 | 284 | $table[$index1][$index2] = |
286 | 285 | max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]); |
287 | 286 | } |
@@ -325,16 +324,14 @@ discard block |
||
325 | 324 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::UNMODIFIED); |
326 | 325 | $index1 --; |
327 | 326 | $index2 --; |
328 | - } |
|
329 | - elseif ( |
|
327 | + } elseif ( |
|
330 | 328 | $index2 > 0 |
331 | 329 | && $table[$index1][$index2] === $table[$index1][$index2 - 1] |
332 | 330 | ) { |
333 | 331 | // update the diff and the indices |
334 | 332 | $diff[] = array($this->sequence2[$index2 + $start - 1], self::INSERTED); |
335 | 333 | $index2 --; |
336 | - } |
|
337 | - else |
|
334 | + } else |
|
338 | 335 | { |
339 | 336 | // update the diff and the indices |
340 | 337 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::DELETED); |
@@ -15,20 +15,20 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -15,8 +15,8 @@ |
||
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 | } |
@@ -79,23 +79,23 @@ |
||
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( |