19
19
class SideBySide extends HtmlArray
20
20
{
21
21
/**
22
- * Render a and return diff with changes between the two sequences
23
- * displayed side by side.
22
+ * Render a and return diff-view with changes between the two sequences displayed side by side.
24
23
*
25
- * @return string The generated side by side diff.
24
+ * @return string The generated side by side diff-view .
26
25
*/
27
26
public function render (): string
28
27
{
@@ -31,130 +30,177 @@ public function render(): string
31
30
}
32
31
33
32
/**
34
- * Generates a string representation of a predefined table and its head with
35
- * titles from options.
33
+ * Generates a string representation of the opening of a predefined table and its header with titles from options.
36
34
*
37
- * @return string Html code representation of the table's header.
35
+ * @return string HTML code representation of a table's header.
38
36
*/
39
37
public function generateTableHeader (): string
40
38
{
41
- $ html = '<table class="Differences DifferencesSideBySide"> ' ;
42
- $ html .= '<thead> ' ;
43
- $ html .= '<tr> ' ;
44
- $ html .= '<th colspan="2"> ' . $ this ->options ['title_a ' ] . '</th> ' ;
45
- $ html .= '<th colspan="2"> ' . $ this ->options ['title_b ' ] . '</th> ' ;
46
- $ html .= '</tr> ' ;
47
- $ html .= '</thead> ' ;
48
- return $ html ;
39
+ return <<<HTML
40
+ <table class="Differences DifferencesSideBySide">
41
+ <thead>
42
+ <tr>
43
+ <th colspan="2"> {$ this ->options ['title_a ' ]}</th>
44
+ <th colspan="2"> {$ this ->options ['title_b ' ]}</th>
45
+ </tr>
46
+ </thead>
47
+ HTML ;
49
48
}
50
49
51
50
/**
52
- * Generates a string representation of one or more rows of a table of lines of text with no difference.
51
+ * Generates a string representation of table rows showing text with no difference.
52
+ *
53
+ * @param array $change Contains the op-codes about the changes between two blocks.
53
54
*
54
- * @param array &$change Array with data about changes.
55
- * @return string Html code representing one or more rows of text with no difference.
55
+ * @return string HTML code representing table rows showing text with no difference.
56
56
*/
57
- public function generateTableRowsEqual (array & $ change ): string
57
+ public function generateTableRowsEqual (array $ change ): string
58
58
{
59
- $ html = "" ;
59
+ $ html = '' ;
60
+
60
61
foreach ($ change ['base ' ]['lines ' ] as $ no => $ line ) {
61
- $ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
62
- $ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
63
- $ html .= '<tr> ' ;
64
- $ html .= '<th> ' . $ fromLine . '</th> ' ;
65
- $ html .= '<td class="Left"><span> ' . $ line . '</span> </td> ' ;
66
- $ html .= '<th> ' . $ toLine . '</th> ' ;
67
- $ html .= '<td class="Right"><span> ' . $ line . '</span> </td> ' ;
68
- $ html .= '</tr> ' ;
62
+ $ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
63
+ $ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
64
+
65
+ $ html .= <<<HTML
66
+ <tr>
67
+ <th> $ fromLine</th>
68
+ <td class="Left"><span> $ line</span> </td>
69
+ <th> $ toLine</th>
70
+ <td class="Right"><span> $ line</span> </td>
71
+ </tr>
72
+ HTML ;
69
73
}
74
+
70
75
return $ html ;
71
76
}
72
77
73
78
/**
74
- * Generates a string representation of one or more rows of a table of lines, where new text was added.
79
+ * Generates a string representation of table rows showing added text.
80
+ *
81
+ * @param array $change Contains the op-codes about the changes between two blocks of text.
75
82
*
76
- * @param array &$change Array with data about changes.
77
- * @return string Html code representing one or more rows of added text.
83
+ * @return string HTML code representing table rows showing with added text.
78
84
*/
79
- public function generateTableRowsInsert (array & $ change ): string
85
+ public function generateTableRowsInsert (array $ change ): string
80
86
{
81
- $ html = "" ;
87
+ $ html = '' ;
88
+
82
89
foreach ($ change ['changed ' ]['lines ' ] as $ no => $ line ) {
83
90
$ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
84
- $ html .= '<tr> ' ;
85
- $ html .= '<th> </th> ' ;
86
- $ html .= '<td class="Left"> </td> ' ;
87
- $ html .= '<th> ' . $ toLine . '</th> ' ;
88
- $ html .= '<td class="Right"><ins> ' . $ line . '</ins> </td> ' ;
89
- $ html .= '</tr> ' ;
91
+
92
+ $ html .= <<<HTML
93
+ <tr>
94
+ <th> </th>
95
+ <td class="Left"> </td>
96
+ <th> $ toLine</th>
97
+ <td class="Right">
98
+ <ins> $ line</ins>
99
+
100
+ </td>
101
+ </tr>
102
+ HTML ;
90
103
}
104
+
91
105
return $ html ;
92
106
}
93
107
94
108
/**
95
- * Generates a string representation of one or more rows of a table of lines, where text was removed .
109
+ * Generates a string representation of table rows showing removed text.
96
110
*
97
- * @param array &$change Array with data about changes.
98
- * @return string Html code representing one or more rows of removed text.
111
+ * @param array $change Contains the op-codes about the changes between two blocks of text.
112
+ *
113
+ * @return string HTML code representing table rows showing removed text.
99
114
*/
100
115
public function generateTableRowsDelete (array &$ change ): string
101
116
{
102
- $ html = "" ;
117
+ $ html = '' ;
118
+
103
119
foreach ($ change ['base ' ]['lines ' ] as $ no => $ line ) {
104
120
$ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
105
- $ html .= '<tr> ' ;
106
- $ html .= '<th> ' . $ fromLine . '</th> ' ;
107
- $ html .= '<td class="Left"><del> ' . $ line . '</del> </td> ' ;
108
- $ html .= '<th> </th> ' ;
109
- $ html .= '<td class="Right"> </td> ' ;
110
- $ html .= '</tr> ' ;
121
+
122
+ $ html = <<<HTML
123
+ <tr>
124
+ <th> $ fromLine</th>
125
+ <td class="Left">
126
+ <del> $ line</del>
127
+
128
+ </td>
129
+ <th> </th>
130
+ <td class="Right"> </td>
131
+ </tr>
132
+ HTML ;
111
133
}
134
+
112
135
return $ html ;
113
136
}
114
137
115
138
/**
116
- * Generates a string representation of one or more rows of a table of lines, where text was partially modified.
139
+ * Generates a string representation of table rows showing partialy modified text.
140
+ *
141
+ * @param array $change Contains the op-codes about the changes between two blocks of text.
117
142
*
118
- * @param array &$change Array with data about changes.
119
- * @return string Html code representing one or more rows of modified.
143
+ * @return string Html code representing table rows showing modified text.
120
144
*/
121
145
public function generateTableRowsReplace (array &$ change ): string
122
146
{
123
- $ html = "" ;
147
+ $ html = '' ;
124
148
125
149
if (count ($ change ['base ' ]['lines ' ]) >= count ($ change ['changed ' ]['lines ' ])) {
126
150
foreach ($ change ['base ' ]['lines ' ] as $ no => $ line ) {
127
- $ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
128
- $ html .= '<tr> ' ;
129
- $ html .= '<th> ' . $ fromLine . '</th> ' ;
130
- $ html .= '<td class="Left"><span> ' . $ line . '</span> </td> ' ;
151
+ $ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
152
+
153
+ $ html .= <<<HTML
154
+ <tr>
155
+ <th> $ fromLine</th>
156
+ <td class="Left">
157
+ <span> $ line</span>
158
+
159
+ </td>
160
+ HTML ;
161
+
131
162
if (!isset ($ change ['changed ' ]['lines ' ][$ no ])) {
132
- $ toLine = '   ' ;
133
- $ changedLine = '   ' ;
163
+ $ toLine = " " ;
164
+ $ changedLine = " " ;
134
165
} else {
135
- $ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
136
- $ changedLine = ' <span> ' . $ change ['changed ' ]['lines ' ][$ no ] . ' </span> ' ;
166
+ $ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
167
+ $ changedLine = " <span> { $ change ['changed ' ]['lines ' ][$ no ]} </span> " ;
137
168
}
138
- $ html .= '<th> ' . $ toLine . '</th> ' ;
139
- $ html .= '<td class="Right"> ' . $ changedLine . '</td> ' ;
140
- $ html .= '</tr> ' ;
169
+
170
+ $ html .= <<<HTML
171
+ <th> $ toLine</th>
172
+ <td class="Right"> $ changedLine</td>
173
+ </tr>
174
+ HTML ;
141
175
}
142
176
} else {
143
177
foreach ($ change ['changed ' ]['lines ' ] as $ no => $ changedLine ) {
144
178
if (!isset ($ change ['base ' ]['lines ' ][$ no ])) {
145
- $ fromLine = '   ' ;
146
- $ line = '   ' ;
179
+ $ fromLine = " " ;
180
+ $ line = " " ;
147
181
} else {
148
- $ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
149
- $ line = ' <span> ' . $ change ['base ' ]['lines ' ][$ no ] . ' </span> ' ;
182
+ $ fromLine = $ change ['base ' ]['offset ' ] + $ no + 1 ;
183
+ $ line = " <span> { $ change ['base ' ]['lines ' ][$ no ]} </span> " ;
150
184
}
151
- $ html .= '<tr> ' ;
152
- $ html .= '<th> ' . $ fromLine . '</th> ' ;
153
- $ html .= '<td class="Left"><span> ' . $ line . '</span> </td> ' ;
154
- $ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
155
- $ html .= '<th> ' . $ toLine . '</th> ' ;
156
- $ html .= '<td class="Right"> ' . $ changedLine . '</td> ' ;
157
- $ html .= '</tr> ' ;
185
+
186
+ $ html .= <<<HTML
187
+ <tr>
188
+ <th> $ fromLine</th>
189
+ <td class="Left">
190
+ <span> $ line</span>
191
+
192
+ </td>
193
+ HTML ;
194
+
195
+ $ toLine = $ change ['changed ' ]['offset ' ] + $ no + 1 ;
196
+
197
+ $ html .= <<<HTML
198
+ <th> $ toLine</th>
199
+ <td class="Right">
200
+ <span> $ changedLine</span>
201
+ </td>
202
+ </tr>
203
+ HTML ;
158
204
}
159
205
}
160
206
0 commit comments