@@ -37,34 +37,34 @@ discard block |
||
| 37 | 37 | const DELETED = 1; |
| 38 | 38 | const INSERTED = 2; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var boolean |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var boolean |
|
| 42 | + */ |
|
| 43 | 43 | private $compareCharacters = false; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | 48 | private $string1; |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | 53 | private $string2; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var string|string[] |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @var string|string[] |
|
| 57 | + */ |
|
| 58 | 58 | private $sequence1 = ''; |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var string|string[] |
|
| 62 | - */ |
|
| 60 | + /** |
|
| 61 | + * @var string|string[] |
|
| 62 | + */ |
|
| 63 | 63 | private $sequence2 = ''; |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var boolean |
|
| 67 | - */ |
|
| 65 | + /** |
|
| 66 | + * @var boolean |
|
| 67 | + */ |
|
| 68 | 68 | private $disposed = false; |
| 69 | 69 | |
| 70 | 70 | public function __construct(string $string1, string $string2) |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | $this->string2 = $string2; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Sets whether to compare single characters. Default is to |
|
| 78 | - * compare only lines. |
|
| 79 | - * |
|
| 80 | - * @param bool $compare |
|
| 81 | - * @return Diff |
|
| 82 | - */ |
|
| 76 | + /** |
|
| 77 | + * Sets whether to compare single characters. Default is to |
|
| 78 | + * compare only lines. |
|
| 79 | + * |
|
| 80 | + * @param bool $compare |
|
| 81 | + * @return Diff |
|
| 82 | + */ |
|
| 83 | 83 | public function setCompareCharacters(bool $compare=true) : Diff |
| 84 | 84 | { |
| 85 | 85 | $this->compareCharacters = $compare; |
@@ -87,19 +87,19 @@ discard block |
||
| 87 | 87 | return $this; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Returns the diff for two strings. The return value is an array, each of |
|
| 92 | - * whose values is an array containing two values: a line (or character, if |
|
| 93 | - * $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the |
|
| 94 | - * line or character is in both strings), DIFF::DELETED (the line or character |
|
| 95 | - * is only in the first string), and DIFF::INSERTED (the line or character is |
|
| 96 | - * only in the second string). |
|
| 97 | - * |
|
| 98 | - * @param string $string1 |
|
| 99 | - * @param string $string2 |
|
| 100 | - * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise) |
|
| 101 | - * @return Diff |
|
| 102 | - */ |
|
| 90 | + /** |
|
| 91 | + * Returns the diff for two strings. The return value is an array, each of |
|
| 92 | + * whose values is an array containing two values: a line (or character, if |
|
| 93 | + * $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the |
|
| 94 | + * line or character is in both strings), DIFF::DELETED (the line or character |
|
| 95 | + * is only in the first string), and DIFF::INSERTED (the line or character is |
|
| 96 | + * only in the second string). |
|
| 97 | + * |
|
| 98 | + * @param string $string1 |
|
| 99 | + * @param string $string2 |
|
| 100 | + * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise) |
|
| 101 | + * @return Diff |
|
| 102 | + */ |
|
| 103 | 103 | public static function compareStrings(string $string1, string $string2, bool $compareCharacters = false) : Diff |
| 104 | 104 | { |
| 105 | 105 | $diff = new Diff($string1, $string2); |
@@ -107,16 +107,16 @@ discard block |
||
| 107 | 107 | return $diff; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Like {@see Diff::compare()}, but returns the diff for two files. |
|
| 112 | - * |
|
| 113 | - * @param string $file1 |
|
| 114 | - * @param string $file2 |
|
| 115 | - * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise) |
|
| 116 | - * @return Diff |
|
| 117 | - * |
|
| 118 | - * @throws FileHelper_Exception If one of the files cannot be found or opened. |
|
| 119 | - */ |
|
| 110 | + /** |
|
| 111 | + * Like {@see Diff::compare()}, but returns the diff for two files. |
|
| 112 | + * |
|
| 113 | + * @param string $file1 |
|
| 114 | + * @param string $file2 |
|
| 115 | + * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise) |
|
| 116 | + * @return Diff |
|
| 117 | + * |
|
| 118 | + * @throws FileHelper_Exception If one of the files cannot be found or opened. |
|
| 119 | + */ |
|
| 120 | 120 | public static function compareFiles(string $file1, string $file2, bool $compareCharacters = false) : Diff |
| 121 | 121 | { |
| 122 | 122 | return self::compareStrings( |
@@ -126,49 +126,49 @@ discard block |
||
| 126 | 126 | ); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Creates an instance of the styler class, which |
|
| 131 | - * is used to access the CSS used for the syntax |
|
| 132 | - * highlighting in the HTML renderers. |
|
| 133 | - * |
|
| 134 | - * @return Styler |
|
| 135 | - */ |
|
| 129 | + /** |
|
| 130 | + * Creates an instance of the styler class, which |
|
| 131 | + * is used to access the CSS used for the syntax |
|
| 132 | + * highlighting in the HTML renderers. |
|
| 133 | + * |
|
| 134 | + * @return Styler |
|
| 135 | + */ |
|
| 136 | 136 | public static function createStyler() : Styler |
| 137 | 137 | { |
| 138 | 138 | return new Styler(); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Retrieves the raw array that contains the diff definitions |
|
| 143 | - * for the two strings. |
|
| 144 | - * |
|
| 145 | - * For example, comparing the following strings: |
|
| 146 | - * |
|
| 147 | - * Hello word |
|
| 148 | - * Hello world |
|
| 149 | - * |
|
| 150 | - * Will return the following array: |
|
| 151 | - * |
|
| 152 | - * <pre> |
|
| 153 | - * Array( |
|
| 154 | - * [0] => Array |
|
| 155 | - * ( |
|
| 156 | - * [0] => Hello word |
|
| 157 | - * [1] => 1 |
|
| 158 | - * ) |
|
| 159 | - * [1] => Array |
|
| 160 | - * ( |
|
| 161 | - * [0] => Hello world |
|
| 162 | - * [1] => 2 |
|
| 163 | - * ) |
|
| 164 | - * ) |
|
| 165 | - * </pre> |
|
| 166 | - * |
|
| 167 | - * Where the second entry in the sub-array is the status |
|
| 168 | - * code, e.g. Diff::DELETED, Diff::INSERTED. |
|
| 169 | - * |
|
| 170 | - * @return array<int,array<int,int|string>> |
|
| 171 | - */ |
|
| 141 | + /** |
|
| 142 | + * Retrieves the raw array that contains the diff definitions |
|
| 143 | + * for the two strings. |
|
| 144 | + * |
|
| 145 | + * For example, comparing the following strings: |
|
| 146 | + * |
|
| 147 | + * Hello word |
|
| 148 | + * Hello world |
|
| 149 | + * |
|
| 150 | + * Will return the following array: |
|
| 151 | + * |
|
| 152 | + * <pre> |
|
| 153 | + * Array( |
|
| 154 | + * [0] => Array |
|
| 155 | + * ( |
|
| 156 | + * [0] => Hello word |
|
| 157 | + * [1] => 1 |
|
| 158 | + * ) |
|
| 159 | + * [1] => Array |
|
| 160 | + * ( |
|
| 161 | + * [0] => Hello world |
|
| 162 | + * [1] => 2 |
|
| 163 | + * ) |
|
| 164 | + * ) |
|
| 165 | + * </pre> |
|
| 166 | + * |
|
| 167 | + * Where the second entry in the sub-array is the status |
|
| 168 | + * code, e.g. Diff::DELETED, Diff::INSERTED. |
|
| 169 | + * |
|
| 170 | + * @return array<int,array<int,int|string>> |
|
| 171 | + */ |
|
| 172 | 172 | public function toArray() : array |
| 173 | 173 | { |
| 174 | 174 | if($this->disposed) |
@@ -242,13 +242,13 @@ discard block |
||
| 242 | 242 | return $diff; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Splits the string into individual characters. |
|
| 247 | - * |
|
| 248 | - * @param string $string |
|
| 249 | - * @throws DiffException |
|
| 250 | - * @return string[] |
|
| 251 | - */ |
|
| 245 | + /** |
|
| 246 | + * Splits the string into individual characters. |
|
| 247 | + * |
|
| 248 | + * @param string $string |
|
| 249 | + * @throws DiffException |
|
| 250 | + * @return string[] |
|
| 251 | + */ |
|
| 252 | 252 | private function splitString(string $string) : array |
| 253 | 253 | { |
| 254 | 254 | $split = preg_split('/\R/', $string); |
@@ -265,15 +265,15 @@ discard block |
||
| 265 | 265 | ); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Returns the table of longest common subsequence lengths for |
|
| 270 | - * the specified sequences. |
|
| 271 | - * |
|
| 272 | - * @param int $start |
|
| 273 | - * @param int $end1 |
|
| 274 | - * @param int $end2 |
|
| 275 | - * @return array<int,array<int,int>> |
|
| 276 | - */ |
|
| 268 | + /** |
|
| 269 | + * Returns the table of longest common subsequence lengths for |
|
| 270 | + * the specified sequences. |
|
| 271 | + * |
|
| 272 | + * @param int $start |
|
| 273 | + * @param int $end1 |
|
| 274 | + * @param int $end2 |
|
| 275 | + * @return array<int,array<int,int>> |
|
| 276 | + */ |
|
| 277 | 277 | private function computeTable(int $start, int $end1, int $end2) : array |
| 278 | 278 | { |
| 279 | 279 | // determine the lengths to be compared |
@@ -307,14 +307,14 @@ discard block |
||
| 307 | 307 | return $table; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * Returns the partial diff for the specificed sequences, in reverse order. |
|
| 312 | - * |
|
| 313 | - * @param int $start |
|
| 314 | - * @param int $end1 |
|
| 315 | - * @param int $end2 |
|
| 316 | - * @return array<int,array<int,int|string>> |
|
| 317 | - */ |
|
| 310 | + /** |
|
| 311 | + * Returns the partial diff for the specificed sequences, in reverse order. |
|
| 312 | + * |
|
| 313 | + * @param int $start |
|
| 314 | + * @param int $end1 |
|
| 315 | + * @param int $end2 |
|
| 316 | + * @return array<int,array<int,int|string>> |
|
| 317 | + */ |
|
| 318 | 318 | private function generatePartialDiff(int $start, int $end1, int $end2) : array |
| 319 | 319 | { |
| 320 | 320 | // compute the table of longest common subsequence lengths |
@@ -361,13 +361,13 @@ discard block |
||
| 361 | 361 | return $diff; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - /** |
|
| 365 | - * Returns a diff as a string, where unmodified lines are prefixed by ' ', |
|
| 366 | - * deletions are prefixed by '- ', and insertions are prefixed by '+ '. |
|
| 367 | - * |
|
| 368 | - * @param string $separator |
|
| 369 | - * @return string |
|
| 370 | - */ |
|
| 364 | + /** |
|
| 365 | + * Returns a diff as a string, where unmodified lines are prefixed by ' ', |
|
| 366 | + * deletions are prefixed by '- ', and insertions are prefixed by '+ '. |
|
| 367 | + * |
|
| 368 | + * @param string $separator |
|
| 369 | + * @return string |
|
| 370 | + */ |
|
| 371 | 371 | public function toString(string $separator = "\n") : string |
| 372 | 372 | { |
| 373 | 373 | $renderer = new PlainText($this); |
@@ -376,14 +376,14 @@ discard block |
||
| 376 | 376 | return $renderer->render(); |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Returns a diff as an HTML string, where unmodified lines are contained |
|
| 381 | - * within 'span' elements, deletions are contained within 'del' elements, and |
|
| 382 | - * insertions are contained within 'ins' elements. |
|
| 383 | - * |
|
| 384 | - * @param string $separator |
|
| 385 | - * @return string |
|
| 386 | - */ |
|
| 379 | + /** |
|
| 380 | + * Returns a diff as an HTML string, where unmodified lines are contained |
|
| 381 | + * within 'span' elements, deletions are contained within 'del' elements, and |
|
| 382 | + * insertions are contained within 'ins' elements. |
|
| 383 | + * |
|
| 384 | + * @param string $separator |
|
| 385 | + * @return string |
|
| 386 | + */ |
|
| 387 | 387 | public function toHTML(string $separator = '<br>') : string |
| 388 | 388 | { |
| 389 | 389 | $renderer = new HTML($this); |
@@ -392,13 +392,13 @@ discard block |
||
| 392 | 392 | return $renderer->render(); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - /** |
|
| 396 | - * Returns a diff as an HTML table. |
|
| 397 | - * |
|
| 398 | - * @param string $indentation |
|
| 399 | - * @param string $separator |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 395 | + /** |
|
| 396 | + * Returns a diff as an HTML table. |
|
| 397 | + * |
|
| 398 | + * @param string $indentation |
|
| 399 | + * @param string $separator |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | 402 | public function toHTMLTable(string $indentation = '', string $separator = '<br>') : string |
| 403 | 403 | { |
| 404 | 404 | $renderer = new HTMLTable($this); |
@@ -408,12 +408,12 @@ discard block |
||
| 408 | 408 | return $renderer->render(); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - /** |
|
| 412 | - * Disposes of the diff by clearing the stored strings, |
|
| 413 | - * to free memory until the class is destructed. |
|
| 414 | - * |
|
| 415 | - * @return Diff |
|
| 416 | - */ |
|
| 411 | + /** |
|
| 412 | + * Disposes of the diff by clearing the stored strings, |
|
| 413 | + * to free memory until the class is destructed. |
|
| 414 | + * |
|
| 415 | + * @return Diff |
|
| 416 | + */ |
|
| 417 | 417 | public function dispose() : Diff |
| 418 | 418 | { |
| 419 | 419 | $this->string1 = ''; |