@@ -26,14 +26,14 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | const ERROR_CSS_FILE_NOT_FOUND = 66801; |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 29 | + /** |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | 32 | private $path; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | 37 | private $fileName = 'styles.css'; |
| 38 | 38 | |
| 39 | 39 | public function __construct() |
@@ -56,22 +56,22 @@ discard block |
||
| 56 | 56 | $this->path = $path; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Retrieves the raw CSS source for the highlighting. |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 59 | + /** |
|
| 60 | + * Retrieves the raw CSS source for the highlighting. |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | 64 | public function getCSS() : string |
| 65 | 65 | { |
| 66 | 66 | return FileHelper::readContents($this->path); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Retrieves a fully formed `code` tag with the CSS, |
|
| 71 | - * to inject inline into an HTML document. |
|
| 72 | - * |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 69 | + /** |
|
| 70 | + * Retrieves a fully formed `code` tag with the CSS, |
|
| 71 | + * to inject inline into an HTML document. |
|
| 72 | + * |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | 75 | public function getStyleTag() : string |
| 76 | 76 | { |
| 77 | 77 | return sprintf( |
@@ -80,23 +80,23 @@ discard block |
||
| 80 | 80 | ); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Retrieves the path to the stylesheet file. |
|
| 85 | - * |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 83 | + /** |
|
| 84 | + * Retrieves the path to the stylesheet file. |
|
| 85 | + * |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | 88 | public function getStylesheetPath() : string |
| 89 | 89 | { |
| 90 | 90 | return $this->path; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Retrieves the URL to the stylesheet file, given the |
|
| 95 | - * local URL to the application's vendor folder. |
|
| 96 | - * |
|
| 97 | - * @param string $vendorURL The URL to the vendor folder (must be accessible in the webroot). |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 93 | + /** |
|
| 94 | + * Retrieves the URL to the stylesheet file, given the |
|
| 95 | + * local URL to the application's vendor folder. |
|
| 96 | + * |
|
| 97 | + * @param string $vendorURL The URL to the vendor folder (must be accessible in the webroot). |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | 100 | public function getStylesheetURL(string $vendorURL) : string |
| 101 | 101 | { |
| 102 | 102 | return sprintf( |
@@ -41,7 +41,7 @@ |
||
| 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', |
@@ -8,14 +8,14 @@ |
||
| 8 | 8 | |
| 9 | 9 | class HTML extends Renderer |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 11 | + /** |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | 14 | private $separator = '<br>'; |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | 19 | private $container = '<div class="text-diff-container">%s</div>'; |
| 20 | 20 | |
| 21 | 21 | public function setSeparator(string $separator) : HTML |
@@ -48,8 +48,8 @@ |
||
| 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( |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | |
| 9 | 9 | class PlainText extends Renderer |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 11 | + /** |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | 14 | private $separator = "\n"; |
| 15 | 15 | |
| 16 | 16 | public function setSeparator(string $separator) : PlainText |
@@ -36,9 +36,9 @@ |
||
| 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 |
@@ -149,24 +149,24 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | // extend the HTML with the new row |
| 151 | 151 | $html .= |
| 152 | - $i2. "<tr>". $nl . |
|
| 153 | - $i3. '<td class="text-diff-'.$leftType. '">'. $leftCell . "</td>".$nl. |
|
| 154 | - $i3. '<td class="text-diff-'.$rightType. '">'. $rightCell . "</td>".$nl. |
|
| 155 | - $i2. "</tr>".$nl; |
|
| 152 | + $i2."<tr>".$nl. |
|
| 153 | + $i3.'<td class="text-diff-'.$leftType.'">'.$leftCell."</td>".$nl. |
|
| 154 | + $i3.'<td class="text-diff-'.$rightType.'">'.$rightCell."</td>".$nl. |
|
| 155 | + $i2."</tr>".$nl; |
|
| 156 | 156 | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - return $i1. sprintf($this->container, $nl.$html).$nl; |
|
| 159 | + return $i1.sprintf($this->container, $nl.$html).$nl; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | private function resolveLeftType(string $leftCell, string $rightCell) : string |
| 163 | 163 | { |
| 164 | - if(empty($leftCell)) |
|
| 164 | + if (empty($leftCell)) |
|
| 165 | 165 | { |
| 166 | 166 | return 'empty'; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - else if($leftCell !== $rightCell) |
|
| 169 | + else if ($leftCell !== $rightCell) |
|
| 170 | 170 | { |
| 171 | 171 | return 'del'; |
| 172 | 172 | } |
@@ -176,12 +176,12 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | private function resolveRightType(string $leftCell, string $rightCell) : string |
| 178 | 178 | { |
| 179 | - if(empty($rightCell)) |
|
| 179 | + if (empty($rightCell)) |
|
| 180 | 180 | { |
| 181 | 181 | return 'empty'; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - else if($leftCell !== $rightCell) |
|
| 184 | + else if ($leftCell !== $rightCell) |
|
| 185 | 185 | { |
| 186 | 186 | return 'ins'; |
| 187 | 187 | } |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $this->separator |
| 213 | 213 | ); |
| 214 | 214 | |
| 215 | - $index ++; |
|
| 215 | + $index++; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | return $html; |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | |
| 221 | 221 | private function resolveTag(int $type) : string |
| 222 | 222 | { |
| 223 | - switch($type) |
|
| 223 | + switch ($type) |
|
| 224 | 224 | { |
| 225 | 225 | case Diff::DELETED: return 'del'; |
| 226 | 226 | case Diff::INSERTED: return 'ins'; |
@@ -164,9 +164,7 @@ discard block |
||
| 164 | 164 | if(empty($leftCell)) |
| 165 | 165 | { |
| 166 | 166 | return 'empty'; |
| 167 | - } |
|
| 168 | - |
|
| 169 | - else if($leftCell !== $rightCell) |
|
| 167 | + } else if($leftCell !== $rightCell) |
|
| 170 | 168 | { |
| 171 | 169 | return 'del'; |
| 172 | 170 | } |
@@ -179,9 +177,7 @@ discard block |
||
| 179 | 177 | if(empty($rightCell)) |
| 180 | 178 | { |
| 181 | 179 | return 'empty'; |
| 182 | - } |
|
| 183 | - |
|
| 184 | - else if($leftCell !== $rightCell) |
|
| 180 | + } else if($leftCell !== $rightCell) |
|
| 185 | 181 | { |
| 186 | 182 | return 'ins'; |
| 187 | 183 | } |
@@ -13,40 +13,40 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | private $separator = '<br>'; |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | 19 | private $indentation = ''; |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | 24 | private $tab = ' '; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var array<int, array<int,int|string>> |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var array<int, array<int,int|string>> |
|
| 28 | + */ |
|
| 29 | 29 | private $array; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | 34 | private $nl = PHP_EOL; |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | 39 | private $container = '<table class="text-diff-container">%s</table>'; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Sets the tab character(s) to indent the HTML code with. |
|
| 43 | - * This is used to indent the table's tags beyond the |
|
| 44 | - * base indentation. |
|
| 45 | - * |
|
| 46 | - * @param string $tab |
|
| 47 | - * @return HTMLTable |
|
| 48 | - * @see HTMLTable::setIndentation() |
|
| 49 | - */ |
|
| 41 | + /** |
|
| 42 | + * Sets the tab character(s) to indent the HTML code with. |
|
| 43 | + * This is used to indent the table's tags beyond the |
|
| 44 | + * base indentation. |
|
| 45 | + * |
|
| 46 | + * @param string $tab |
|
| 47 | + * @return HTMLTable |
|
| 48 | + * @see HTMLTable::setIndentation() |
|
| 49 | + */ |
|
| 50 | 50 | public function setTab(string $tab) : HTMLTable |
| 51 | 51 | { |
| 52 | 52 | $this->tab = $tab; |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | return $this->nl; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Sets the character |
|
| 69 | - * @param string $separator |
|
| 70 | - * @return HTMLTable |
|
| 71 | - */ |
|
| 67 | + /** |
|
| 68 | + * Sets the character |
|
| 69 | + * @param string $separator |
|
| 70 | + * @return HTMLTable |
|
| 71 | + */ |
|
| 72 | 72 | public function setSeparator(string $separator) : HTMLTable |
| 73 | 73 | { |
| 74 | 74 | $this->separator = $separator; |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | return $this; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Sets the character(s) to indent the whole table with. |
|
| 81 | - * |
|
| 82 | - * @param string $indent |
|
| 83 | - * @return HTMLTable |
|
| 84 | - * @see HTMLTable::setTab() |
|
| 85 | - */ |
|
| 79 | + /** |
|
| 80 | + * Sets the character(s) to indent the whole table with. |
|
| 81 | + * |
|
| 82 | + * @param string $indent |
|
| 83 | + * @return HTMLTable |
|
| 84 | + * @see HTMLTable::setTab() |
|
| 85 | + */ |
|
| 86 | 86 | public function setIndentation(string $indent) : HTMLTable |
| 87 | 87 | { |
| 88 | 88 | $this->indentation = $indent; |
@@ -100,11 +100,11 @@ discard block |
||
| 100 | 100 | return $this->indentation; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Returns a diff as an HTML table. |
|
| 105 | - * |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 103 | + /** |
|
| 104 | + * Returns a diff as an HTML table. |
|
| 105 | + * |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | 108 | public function render() : string |
| 109 | 109 | { |
| 110 | 110 | $this->array = $this->diff->toArray(); |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | return 'unmodified'; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Returns the content of the cell. |
|
| 196 | - * |
|
| 197 | - * @param int $index |
|
| 198 | - * @param int $type The operation type (inset/delete/unmodified) |
|
| 199 | - * @return string |
|
| 200 | - */ |
|
| 194 | + /** |
|
| 195 | + * Returns the content of the cell. |
|
| 196 | + * |
|
| 197 | + * @param int $index |
|
| 198 | + * @param int $type The operation type (inset/delete/unmodified) |
|
| 199 | + * @return string |
|
| 200 | + */ |
|
| 201 | 201 | private function getCellContent(int &$index, int $type) : string |
| 202 | 202 | { |
| 203 | 203 | // initialise the HTML |
@@ -6,9 +6,9 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | abstract class Renderer |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var Diff |
|
| 11 | - */ |
|
| 9 | + /** |
|
| 10 | + * @var Diff |
|
| 11 | + */ |
|
| 12 | 12 | protected $diff; |
| 13 | 13 | |
| 14 | 14 | public function __construct(Diff $diff) |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | $this->diff = $diff; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return mixed |
|
| 21 | - */ |
|
| 19 | + /** |
|
| 20 | + * @return mixed |
|
| 21 | + */ |
|
| 22 | 22 | abstract public function render(); |
| 23 | 23 | } |
@@ -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 = ''; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @param bool $compare |
| 81 | 81 | * @return Diff |
| 82 | 82 | */ |
| 83 | - public function setCompareCharacters(bool $compare=true) : Diff |
|
| 83 | + public function setCompareCharacters(bool $compare = true) : Diff |
|
| 84 | 84 | { |
| 85 | 85 | $this->compareCharacters = $compare; |
| 86 | 86 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | public function toArray() : array |
| 173 | 173 | { |
| 174 | - if($this->disposed) |
|
| 174 | + if ($this->disposed) |
|
| 175 | 175 | { |
| 176 | 176 | throw new DiffException( |
| 177 | 177 | 'The diff has been disposed.', |
@@ -204,14 +204,14 @@ discard block |
||
| 204 | 204 | // skip any common prefix |
| 205 | 205 | while ($start <= $end1 && $start <= $end2 && $this->sequence1[$start] == $this->sequence2[$start]) |
| 206 | 206 | { |
| 207 | - $start ++; |
|
| 207 | + $start++; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // skip any common suffix |
| 211 | 211 | while ($end1 >= $start && $end2 >= $start && $this->sequence1[$end1] == $this->sequence2[$end2]) |
| 212 | 212 | { |
| 213 | - $end1 --; |
|
| 214 | - $end2 --; |
|
| 213 | + $end1--; |
|
| 214 | + $end2--; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | // generate the partial diff |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | // generate the full diff |
| 221 | 221 | $diff = array(); |
| 222 | 222 | |
| 223 | - for ($index = 0; $index < $start; $index ++) |
|
| 223 | + for ($index = 0; $index < $start; $index++) |
|
| 224 | 224 | { |
| 225 | 225 | $diff[] = array($this->sequence1[$index], self::UNMODIFIED); |
| 226 | 226 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | $diff[] = array_pop($partialDiff); |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - for ($index = $end1 + 1; $index < $totalSequence; $index ++) |
|
| 233 | + for ($index = $end1 + 1; $index < $totalSequence; $index++) |
|
| 234 | 234 | { |
| 235 | 235 | $diff[] = array($this->sequence1[$index], self::UNMODIFIED); |
| 236 | 236 | } |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | $split = preg_split('/\R/', $string); |
| 255 | 255 | |
| 256 | - if(is_array($split)) |
|
| 256 | + if (is_array($split)) |
|
| 257 | 257 | { |
| 258 | 258 | return $split; |
| 259 | 259 | } |
@@ -284,19 +284,19 @@ discard block |
||
| 284 | 284 | $table = array(array_fill(0, $length2 + 1, 0)); |
| 285 | 285 | |
| 286 | 286 | // loop over the rows |
| 287 | - for ($index1 = 1; $index1 <= $length1; $index1 ++){ |
|
| 287 | + for ($index1 = 1; $index1 <= $length1; $index1++) { |
|
| 288 | 288 | |
| 289 | 289 | // create the new row |
| 290 | 290 | $table[$index1] = array(0); |
| 291 | 291 | |
| 292 | 292 | // loop over the columns |
| 293 | - for ($index2 = 1; $index2 <= $length2; $index2 ++){ |
|
| 293 | + for ($index2 = 1; $index2 <= $length2; $index2++) { |
|
| 294 | 294 | |
| 295 | 295 | // store the longest common subsequence length |
| 296 | 296 | if ($this->sequence1[$index1 + $start - 1] |
| 297 | - == $this->sequence2[$index2 + $start - 1]){ |
|
| 297 | + == $this->sequence2[$index2 + $start - 1]) { |
|
| 298 | 298 | $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1; |
| 299 | - }else{ |
|
| 299 | + } else { |
|
| 300 | 300 | $table[$index1][$index2] = |
| 301 | 301 | max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]); |
| 302 | 302 | } |
@@ -335,11 +335,11 @@ discard block |
||
| 335 | 335 | $index1 > 0 && $index2 > 0 |
| 336 | 336 | && $this->sequence1[$index1 + $start - 1] |
| 337 | 337 | == $this->sequence2[$index2 + $start - 1] |
| 338 | - ){ |
|
| 338 | + ) { |
|
| 339 | 339 | // update the diff and the indices |
| 340 | 340 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::UNMODIFIED); |
| 341 | - $index1 --; |
|
| 342 | - $index2 --; |
|
| 341 | + $index1--; |
|
| 342 | + $index2--; |
|
| 343 | 343 | } |
| 344 | 344 | elseif ( |
| 345 | 345 | $index2 > 0 |
@@ -347,13 +347,13 @@ discard block |
||
| 347 | 347 | ) { |
| 348 | 348 | // update the diff and the indices |
| 349 | 349 | $diff[] = array($this->sequence2[$index2 + $start - 1], self::INSERTED); |
| 350 | - $index2 --; |
|
| 350 | + $index2--; |
|
| 351 | 351 | } |
| 352 | 352 | else |
| 353 | 353 | { |
| 354 | 354 | // update the diff and the indices |
| 355 | 355 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::DELETED); |
| 356 | - $index1 --; |
|
| 356 | + $index1--; |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | |
@@ -191,8 +191,7 @@ discard block |
||
| 191 | 191 | $end1 = strlen($this->string1) - 1; |
| 192 | 192 | $end2 = strlen($this->string2) - 1; |
| 193 | 193 | $totalSequence = strlen($this->sequence1); |
| 194 | - } |
|
| 195 | - else |
|
| 194 | + } else |
|
| 196 | 195 | { |
| 197 | 196 | $this->sequence1 = $this->splitString($this->string1); |
| 198 | 197 | $this->sequence2 = $this->splitString($this->string2); |
@@ -296,7 +295,7 @@ discard block |
||
| 296 | 295 | if ($this->sequence1[$index1 + $start - 1] |
| 297 | 296 | == $this->sequence2[$index2 + $start - 1]){ |
| 298 | 297 | $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1; |
| 299 | - }else{ |
|
| 298 | + } else{ |
|
| 300 | 299 | $table[$index1][$index2] = |
| 301 | 300 | max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]); |
| 302 | 301 | } |
@@ -340,16 +339,14 @@ discard block |
||
| 340 | 339 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::UNMODIFIED); |
| 341 | 340 | $index1 --; |
| 342 | 341 | $index2 --; |
| 343 | - } |
|
| 344 | - elseif ( |
|
| 342 | + } elseif ( |
|
| 345 | 343 | $index2 > 0 |
| 346 | 344 | && $table[$index1][$index2] == $table[$index1][$index2 - 1] |
| 347 | 345 | ) { |
| 348 | 346 | // update the diff and the indices |
| 349 | 347 | $diff[] = array($this->sequence2[$index2 + $start - 1], self::INSERTED); |
| 350 | 348 | $index2 --; |
| 351 | - } |
|
| 352 | - else |
|
| 349 | + } else |
|
| 353 | 350 | { |
| 354 | 351 | // update the diff and the indices |
| 355 | 352 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::DELETED); |