@@ -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( |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 = ''; |