@@ -6,9 +6,9 @@ |
||
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) |
@@ -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 |
@@ -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 |
|
28 | - */ |
|
26 | + /** |
|
27 | + * @var array |
|
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; |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | return $this->nl; |
63 | 63 | } |
64 | 64 | |
65 | - /** |
|
66 | - * Sets the character |
|
67 | - * @param string $separator |
|
68 | - * @return HTMLTable |
|
69 | - */ |
|
65 | + /** |
|
66 | + * Sets the character |
|
67 | + * @param string $separator |
|
68 | + * @return HTMLTable |
|
69 | + */ |
|
70 | 70 | public function setSeparator(string $separator) : HTMLTable |
71 | 71 | { |
72 | 72 | $this->separator = $separator; |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | return $this; |
75 | 75 | } |
76 | 76 | |
77 | - /** |
|
78 | - * Sets the character(s) to indent the whole table with. |
|
79 | - * |
|
80 | - * @param string $indent |
|
81 | - * @return HTMLTable |
|
82 | - * @see HTMLTable::setTab() |
|
83 | - */ |
|
77 | + /** |
|
78 | + * Sets the character(s) to indent the whole table with. |
|
79 | + * |
|
80 | + * @param string $indent |
|
81 | + * @return HTMLTable |
|
82 | + * @see HTMLTable::setTab() |
|
83 | + */ |
|
84 | 84 | public function setIndentation(string $indent) : HTMLTable |
85 | 85 | { |
86 | 86 | $this->indentation = $indent; |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | return $this->indentation; |
99 | 99 | } |
100 | 100 | |
101 | - /** |
|
102 | - * Returns a diff as an HTML table. |
|
103 | - * |
|
104 | - * @param array $this->array |
|
105 | - * @param string $indentation |
|
106 | - * @param string $separator |
|
107 | - * @return string |
|
108 | - */ |
|
101 | + /** |
|
102 | + * Returns a diff as an HTML table. |
|
103 | + * |
|
104 | + * @param array $this->array |
|
105 | + * @param string $indentation |
|
106 | + * @param string $separator |
|
107 | + * @return string |
|
108 | + */ |
|
109 | 109 | public function render() : string |
110 | 110 | { |
111 | 111 | $this->array = $this->diff->toArray(); |
@@ -189,13 +189,13 @@ discard block |
||
189 | 189 | return 'unmodified'; |
190 | 190 | } |
191 | 191 | |
192 | - /** |
|
193 | - * Returns the content of the cell. |
|
194 | - * |
|
195 | - * @param int $index |
|
196 | - * @param int $type The operation type (inset/delete/unmodified) |
|
197 | - * @return string |
|
198 | - */ |
|
192 | + /** |
|
193 | + * Returns the content of the cell. |
|
194 | + * |
|
195 | + * @param int $index |
|
196 | + * @param int $type The operation type (inset/delete/unmodified) |
|
197 | + * @return string |
|
198 | + */ |
|
199 | 199 | private function getCellContent(int &$index, int $type) : string |
200 | 200 | { |
201 | 201 | // initialise the HTML |
@@ -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 | } |
@@ -36,34 +36,34 @@ discard block |
||
36 | 36 | const DELETED = 1; |
37 | 37 | const INSERTED = 2; |
38 | 38 | |
39 | - /** |
|
40 | - * @var boolean |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var boolean |
|
41 | + */ |
|
42 | 42 | private $compareCharacters = false; |
43 | 43 | |
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | 47 | private $string1; |
48 | 48 | |
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | 52 | private $string2; |
53 | 53 | |
54 | - /** |
|
55 | - * @var string|string[] |
|
56 | - */ |
|
54 | + /** |
|
55 | + * @var string|string[] |
|
56 | + */ |
|
57 | 57 | private $sequence1 = ''; |
58 | 58 | |
59 | - /** |
|
60 | - * @var string|string[] |
|
61 | - */ |
|
59 | + /** |
|
60 | + * @var string|string[] |
|
61 | + */ |
|
62 | 62 | private $sequence2 = ''; |
63 | 63 | |
64 | - /** |
|
65 | - * @var boolean |
|
66 | - */ |
|
64 | + /** |
|
65 | + * @var boolean |
|
66 | + */ |
|
67 | 67 | private $disposed = false; |
68 | 68 | |
69 | 69 | public function __construct(string $string1, string $string2) |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | $this->string2 = $string2; |
73 | 73 | } |
74 | 74 | |
75 | - /** |
|
76 | - * Sets whether to compare single characters. Default is to |
|
77 | - * compare only lines. |
|
78 | - * |
|
79 | - * @param bool $compare |
|
80 | - * @return Diff |
|
81 | - */ |
|
75 | + /** |
|
76 | + * Sets whether to compare single characters. Default is to |
|
77 | + * compare only lines. |
|
78 | + * |
|
79 | + * @param bool $compare |
|
80 | + * @return Diff |
|
81 | + */ |
|
82 | 82 | public function setCompareCharacters(bool $compare=true) : Diff |
83 | 83 | { |
84 | 84 | $this->compareCharacters = $compare; |
@@ -86,19 +86,19 @@ discard block |
||
86 | 86 | return $this; |
87 | 87 | } |
88 | 88 | |
89 | - /** |
|
90 | - * Returns the diff for two strings. The return value is an array, each of |
|
91 | - * whose values is an array containing two values: a line (or character, if |
|
92 | - * $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the |
|
93 | - * line or character is in both strings), DIFF::DELETED (the line or character |
|
94 | - * is only in the first string), and DIFF::INSERTED (the line or character is |
|
95 | - * only in the second string). |
|
96 | - * |
|
97 | - * @param string $string1 |
|
98 | - * @param string $string2 |
|
99 | - * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise) |
|
100 | - * @return Diff |
|
101 | - */ |
|
89 | + /** |
|
90 | + * Returns the diff for two strings. The return value is an array, each of |
|
91 | + * whose values is an array containing two values: a line (or character, if |
|
92 | + * $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the |
|
93 | + * line or character is in both strings), DIFF::DELETED (the line or character |
|
94 | + * is only in the first string), and DIFF::INSERTED (the line or character is |
|
95 | + * only in the second string). |
|
96 | + * |
|
97 | + * @param string $string1 |
|
98 | + * @param string $string2 |
|
99 | + * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise) |
|
100 | + * @return Diff |
|
101 | + */ |
|
102 | 102 | public static function compareStrings(string $string1, string $string2, bool $compareCharacters = false) : Diff |
103 | 103 | { |
104 | 104 | $diff = new Diff($string1, $string2); |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | return $diff; |
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * Like {@see Diff::compare()}, but returns the diff for two files. |
|
111 | - * |
|
112 | - * @param string $file1 |
|
113 | - * @param string $file2 |
|
114 | - * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise) |
|
115 | - * @return Diff |
|
116 | - * |
|
117 | - * @throws FileHelper_Exception If one of the files cannot be found or opened. |
|
118 | - */ |
|
109 | + /** |
|
110 | + * Like {@see Diff::compare()}, but returns the diff for two files. |
|
111 | + * |
|
112 | + * @param string $file1 |
|
113 | + * @param string $file2 |
|
114 | + * @param bool $compareCharacters Whether to compare single characters (compares lines otherwise) |
|
115 | + * @return Diff |
|
116 | + * |
|
117 | + * @throws FileHelper_Exception If one of the files cannot be found or opened. |
|
118 | + */ |
|
119 | 119 | public static function compareFiles(string $file1, string $file2, bool $compareCharacters = false) : Diff |
120 | 120 | { |
121 | 121 | return self::compare( |
@@ -125,49 +125,49 @@ discard block |
||
125 | 125 | ); |
126 | 126 | } |
127 | 127 | |
128 | - /** |
|
129 | - * Creates an instance of the styler class, which |
|
130 | - * is used to access the CSS used for the syntax |
|
131 | - * highlighting in the HTML renderers. |
|
132 | - * |
|
133 | - * @return Styler |
|
134 | - */ |
|
128 | + /** |
|
129 | + * Creates an instance of the styler class, which |
|
130 | + * is used to access the CSS used for the syntax |
|
131 | + * highlighting in the HTML renderers. |
|
132 | + * |
|
133 | + * @return Styler |
|
134 | + */ |
|
135 | 135 | public static function createStyler() : Styler |
136 | 136 | { |
137 | 137 | return new Styler(); |
138 | 138 | } |
139 | 139 | |
140 | - /** |
|
141 | - * Retrieves the raw array that contains the diff definitions |
|
142 | - * for the two strings. |
|
143 | - * |
|
144 | - * For example, comparing the following strings: |
|
145 | - * |
|
146 | - * Hello word |
|
147 | - * Hello world |
|
148 | - * |
|
149 | - * Will return the following array: |
|
150 | - * |
|
151 | - * <pre> |
|
152 | - * Array( |
|
153 | - * [0] => Array |
|
154 | - * ( |
|
155 | - * [0] => Hello word |
|
156 | - * [1] => 1 |
|
157 | - * ) |
|
158 | - * [1] => Array |
|
159 | - * ( |
|
160 | - * [0] => Hello world |
|
161 | - * [1] => 2 |
|
162 | - * ) |
|
163 | - * ) |
|
164 | - * </pre> |
|
165 | - * |
|
166 | - * Where the second entry in the sub-array is the status |
|
167 | - * code, e.g. Diff::DELETED, Diff::INSERTED. |
|
168 | - * |
|
169 | - * @return array<int,array<int,mixed>> |
|
170 | - */ |
|
140 | + /** |
|
141 | + * Retrieves the raw array that contains the diff definitions |
|
142 | + * for the two strings. |
|
143 | + * |
|
144 | + * For example, comparing the following strings: |
|
145 | + * |
|
146 | + * Hello word |
|
147 | + * Hello world |
|
148 | + * |
|
149 | + * Will return the following array: |
|
150 | + * |
|
151 | + * <pre> |
|
152 | + * Array( |
|
153 | + * [0] => Array |
|
154 | + * ( |
|
155 | + * [0] => Hello word |
|
156 | + * [1] => 1 |
|
157 | + * ) |
|
158 | + * [1] => Array |
|
159 | + * ( |
|
160 | + * [0] => Hello world |
|
161 | + * [1] => 2 |
|
162 | + * ) |
|
163 | + * ) |
|
164 | + * </pre> |
|
165 | + * |
|
166 | + * Where the second entry in the sub-array is the status |
|
167 | + * code, e.g. Diff::DELETED, Diff::INSERTED. |
|
168 | + * |
|
169 | + * @return array<int,array<int,mixed>> |
|
170 | + */ |
|
171 | 171 | public function toArray() : array |
172 | 172 | { |
173 | 173 | if($this->disposed) |
@@ -242,15 +242,15 @@ discard block |
||
242 | 242 | return $diff; |
243 | 243 | } |
244 | 244 | |
245 | - /** |
|
246 | - * Returns the table of longest common subsequence lengths for |
|
247 | - * the specified sequences. |
|
248 | - * |
|
249 | - * @param int $start |
|
250 | - * @param int $end1 |
|
251 | - * @param int $end2 |
|
252 | - * @return array<int,array<int,int>> |
|
253 | - */ |
|
245 | + /** |
|
246 | + * Returns the table of longest common subsequence lengths for |
|
247 | + * the specified sequences. |
|
248 | + * |
|
249 | + * @param int $start |
|
250 | + * @param int $end1 |
|
251 | + * @param int $end2 |
|
252 | + * @return array<int,array<int,int>> |
|
253 | + */ |
|
254 | 254 | private function computeTable(int $start, int $end1, int $end2) : array |
255 | 255 | { |
256 | 256 | // determine the lengths to be compared |
@@ -284,13 +284,13 @@ discard block |
||
284 | 284 | return $table; |
285 | 285 | } |
286 | 286 | |
287 | - /** |
|
288 | - * Returns the partial diff for the specificed sequences, in reverse order. |
|
289 | - * |
|
290 | - * @param array<int,array<int,int>> $table |
|
291 | - * @param int $start |
|
292 | - * @return array<int,array<int,string>> |
|
293 | - */ |
|
287 | + /** |
|
288 | + * Returns the partial diff for the specificed sequences, in reverse order. |
|
289 | + * |
|
290 | + * @param array<int,array<int,int>> $table |
|
291 | + * @param int $start |
|
292 | + * @return array<int,array<int,string>> |
|
293 | + */ |
|
294 | 294 | private function generatePartialDiff(array $table, int $start) : array |
295 | 295 | { |
296 | 296 | // initialise the diff |
@@ -334,14 +334,14 @@ discard block |
||
334 | 334 | return $diff; |
335 | 335 | } |
336 | 336 | |
337 | - /** |
|
338 | - * Returns a diff as a string, where unmodified lines are prefixed by ' ', |
|
339 | - * deletions are prefixed by '- ', and insertions are prefixed by '+ '. |
|
340 | - * |
|
341 | - * @param array $diff |
|
342 | - * @param string $separator |
|
343 | - * @return string |
|
344 | - */ |
|
337 | + /** |
|
338 | + * Returns a diff as a string, where unmodified lines are prefixed by ' ', |
|
339 | + * deletions are prefixed by '- ', and insertions are prefixed by '+ '. |
|
340 | + * |
|
341 | + * @param array $diff |
|
342 | + * @param string $separator |
|
343 | + * @return string |
|
344 | + */ |
|
345 | 345 | public function toString(string $separator = "\n") : string |
346 | 346 | { |
347 | 347 | $renderer = new PlainText($this); |
@@ -350,15 +350,15 @@ discard block |
||
350 | 350 | return $renderer->render(); |
351 | 351 | } |
352 | 352 | |
353 | - /** |
|
354 | - * Returns a diff as an HTML string, where unmodified lines are contained |
|
355 | - * within 'span' elements, deletions are contained within 'del' elements, and |
|
356 | - * insertions are contained within 'ins' elements. |
|
357 | - * |
|
358 | - * @param array $diff |
|
359 | - * @param string $separator |
|
360 | - * @return string |
|
361 | - */ |
|
353 | + /** |
|
354 | + * Returns a diff as an HTML string, where unmodified lines are contained |
|
355 | + * within 'span' elements, deletions are contained within 'del' elements, and |
|
356 | + * insertions are contained within 'ins' elements. |
|
357 | + * |
|
358 | + * @param array $diff |
|
359 | + * @param string $separator |
|
360 | + * @return string |
|
361 | + */ |
|
362 | 362 | public function toHTML(string $separator = '<br>') : string |
363 | 363 | { |
364 | 364 | $renderer = new HTML($this); |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | return $renderer->render(); |
368 | 368 | } |
369 | 369 | |
370 | - /** |
|
371 | - * Returns a diff as an HTML table. |
|
372 | - * |
|
373 | - * @param array $diff |
|
374 | - * @param string $indentation |
|
375 | - * @param string $separator |
|
376 | - * @return string |
|
377 | - */ |
|
370 | + /** |
|
371 | + * Returns a diff as an HTML table. |
|
372 | + * |
|
373 | + * @param array $diff |
|
374 | + * @param string $indentation |
|
375 | + * @param string $separator |
|
376 | + * @return string |
|
377 | + */ |
|
378 | 378 | public function toHTMLTable(string $indentation = '', string $separator = '<br>') : string |
379 | 379 | { |
380 | 380 | $renderer = new HTMLTable($this); |
@@ -384,12 +384,12 @@ discard block |
||
384 | 384 | return $renderer->render(); |
385 | 385 | } |
386 | 386 | |
387 | - /** |
|
388 | - * Disposes of the diff by clearing the stored strings, |
|
389 | - * to free memory until the class is destructed. |
|
390 | - * |
|
391 | - * @return Diff |
|
392 | - */ |
|
387 | + /** |
|
388 | + * Disposes of the diff by clearing the stored strings, |
|
389 | + * to free memory until the class is destructed. |
|
390 | + * |
|
391 | + * @return Diff |
|
392 | + */ |
|
393 | 393 | public function dispose() : Diff |
394 | 394 | { |
395 | 395 | $this->string1 = ''; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param bool $compare |
80 | 80 | * @return Diff |
81 | 81 | */ |
82 | - public function setCompareCharacters(bool $compare=true) : Diff |
|
82 | + public function setCompareCharacters(bool $compare = true) : Diff |
|
83 | 83 | { |
84 | 84 | $this->compareCharacters = $compare; |
85 | 85 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function toArray() : array |
172 | 172 | { |
173 | - if($this->disposed) |
|
173 | + if ($this->disposed) |
|
174 | 174 | { |
175 | 175 | throw new DiffException( |
176 | 176 | 'The diff has been disposed.', |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | // skip any common prefix |
201 | 201 | while ($start <= $end1 && $start <= $end2 && $this->sequence1[$start] == $this->sequence2[$start]) |
202 | 202 | { |
203 | - $start ++; |
|
203 | + $start++; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // skip any common suffix |
207 | 207 | while ($end1 >= $start && $end2 >= $start && $this->sequence1[$end1] == $this->sequence2[$end2]) |
208 | 208 | { |
209 | - $end1 --; |
|
210 | - $end2 --; |
|
209 | + $end1--; |
|
210 | + $end2--; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | // compute the table of longest common subsequence lengths |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | // generate the full diff |
220 | 220 | $diff = array(); |
221 | 221 | |
222 | - for ($index = 0; $index < $start; $index ++) |
|
222 | + for ($index = 0; $index < $start; $index++) |
|
223 | 223 | { |
224 | 224 | $diff[] = array($this->sequence1[$index], self::UNMODIFIED); |
225 | 225 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | |
232 | 232 | $max = ($this->compareCharacters ? strlen($this->sequence1) : count($this->sequence1)); |
233 | 233 | |
234 | - for ($index = $end1 + 1; $index < $max; $index ++) |
|
234 | + for ($index = $end1 + 1; $index < $max; $index++) |
|
235 | 235 | { |
236 | 236 | $diff[] = array($this->sequence1[$index], self::UNMODIFIED); |
237 | 237 | } |
@@ -261,19 +261,19 @@ discard block |
||
261 | 261 | $table = array(array_fill(0, $length2 + 1, 0)); |
262 | 262 | |
263 | 263 | // loop over the rows |
264 | - for ($index1 = 1; $index1 <= $length1; $index1 ++){ |
|
264 | + for ($index1 = 1; $index1 <= $length1; $index1++) { |
|
265 | 265 | |
266 | 266 | // create the new row |
267 | 267 | $table[$index1] = array(0); |
268 | 268 | |
269 | 269 | // loop over the columns |
270 | - for ($index2 = 1; $index2 <= $length2; $index2 ++){ |
|
270 | + for ($index2 = 1; $index2 <= $length2; $index2++) { |
|
271 | 271 | |
272 | 272 | // store the longest common subsequence length |
273 | 273 | if ($this->sequence1[$index1 + $start - 1] |
274 | - == $this->sequence2[$index2 + $start - 1]){ |
|
274 | + == $this->sequence2[$index2 + $start - 1]) { |
|
275 | 275 | $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1; |
276 | - }else{ |
|
276 | + } else { |
|
277 | 277 | $table[$index1][$index2] = |
278 | 278 | max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]); |
279 | 279 | } |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | $index1 > 0 && $index2 > 0 |
309 | 309 | && $this->sequence1[$index1 + $start - 1] |
310 | 310 | == $this->sequence2[$index2 + $start - 1] |
311 | - ){ |
|
311 | + ) { |
|
312 | 312 | // update the diff and the indices |
313 | 313 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::UNMODIFIED); |
314 | - $index1 --; |
|
315 | - $index2 --; |
|
314 | + $index1--; |
|
315 | + $index2--; |
|
316 | 316 | } |
317 | 317 | elseif ( |
318 | 318 | $index2 > 0 |
@@ -320,13 +320,13 @@ discard block |
||
320 | 320 | ) { |
321 | 321 | // update the diff and the indices |
322 | 322 | $diff[] = array($this->sequence2[$index2 + $start - 1], self::INSERTED); |
323 | - $index2 --; |
|
323 | + $index2--; |
|
324 | 324 | } |
325 | 325 | else |
326 | 326 | { |
327 | 327 | // update the diff and the indices |
328 | 328 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::DELETED); |
329 | - $index1 --; |
|
329 | + $index1--; |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 |
@@ -188,8 +188,7 @@ discard block |
||
188 | 188 | $this->sequence2 = $this->string2; |
189 | 189 | $end1 = strlen($this->string1) - 1; |
190 | 190 | $end2 = strlen($this->string2) - 1; |
191 | - } |
|
192 | - else |
|
191 | + } else |
|
193 | 192 | { |
194 | 193 | $this->sequence1 = preg_split('/\R/', $this->string1); |
195 | 194 | $this->sequence2 = preg_split('/\R/', $this->string2); |
@@ -273,7 +272,7 @@ discard block |
||
273 | 272 | if ($this->sequence1[$index1 + $start - 1] |
274 | 273 | == $this->sequence2[$index2 + $start - 1]){ |
275 | 274 | $table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1; |
276 | - }else{ |
|
275 | + } else{ |
|
277 | 276 | $table[$index1][$index2] = |
278 | 277 | max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]); |
279 | 278 | } |
@@ -313,16 +312,14 @@ discard block |
||
313 | 312 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::UNMODIFIED); |
314 | 313 | $index1 --; |
315 | 314 | $index2 --; |
316 | - } |
|
317 | - elseif ( |
|
315 | + } elseif ( |
|
318 | 316 | $index2 > 0 |
319 | 317 | && $table[$index1][$index2] == $table[$index1][$index2 - 1] |
320 | 318 | ) { |
321 | 319 | // update the diff and the indices |
322 | 320 | $diff[] = array($this->sequence2[$index2 + $start - 1], self::INSERTED); |
323 | 321 | $index2 --; |
324 | - } |
|
325 | - else |
|
322 | + } else |
|
326 | 323 | { |
327 | 324 | // update the diff and the indices |
328 | 325 | $diff[] = array($this->sequence1[$index1 + $start - 1], self::DELETED); |