@@ -55,7 +55,7 @@ protected function redererChanges(array $changes): string
55
55
*/
56
56
protected function renderTableHeader (): string
57
57
{
58
- $ colspan = ( $ this ->options ['lineNumbers ' ] ? ' colspan="2" ' : '' ) ;
58
+ $ colspan = $ this ->options ['lineNumbers ' ] ? ' colspan="2" ' : '' ;
59
59
60
60
return
61
61
'<thead> ' .
@@ -71,7 +71,7 @@ protected function renderTableHeader(): string
71
71
*/
72
72
protected function renderTableSeparateBlock (): string
73
73
{
74
- $ colspan = (! $ this ->options ['lineNumbers ' ] ? '2 ' : '4 ' ) ;
74
+ $ colspan = $ this ->options ['lineNumbers ' ] ? '4 ' : '2 ' ;
75
75
76
76
return
77
77
'<tbody class="skipped"> ' .
@@ -121,15 +121,9 @@ protected function renderTableEqual(array $change): string
121
121
122
122
$ html .=
123
123
'<tr> ' .
124
- ($ this ->options ['lineNumbers ' ] ?
125
- '<th class="n-old"> ' . $ oldLineNum . '</th> '
126
- : ''
127
- ) .
124
+ $ this ->renderLineNumberColumn ('old ' , $ oldLineNum ) .
128
125
'<td class="old"> ' . $ oldLine . '</td> ' .
129
- ($ this ->options ['lineNumbers ' ] ?
130
- '<th class="n-new"> ' . $ newLineNum . '</th> '
131
- : ''
132
- ) .
126
+ $ this ->renderLineNumberColumn ('new ' , $ newLineNum ) .
133
127
'<td class="new"> ' . $ newLine . '</td> ' .
134
128
'</tr> ' ;
135
129
}
@@ -151,15 +145,9 @@ protected function renderTableInsert(array $change): string
151
145
152
146
$ html .=
153
147
'<tr> ' .
154
- ($ this ->options ['lineNumbers ' ] ?
155
- '<th></th> '
156
- : ''
157
- ) .
148
+ $ this ->renderLineNumberColumn ('' , null ) .
158
149
'<td class="old"></td> ' .
159
- ($ this ->options ['lineNumbers ' ] ?
160
- '<th class="n-new"> ' . $ newLineNum . '</th> '
161
- : ''
162
- ) .
150
+ $ this ->renderLineNumberColumn ('new ' , $ newLineNum ) .
163
151
'<td class="new"> ' . $ newLine . '</td> ' .
164
152
'</tr> ' ;
165
153
}
@@ -181,15 +169,9 @@ protected function renderTableDelete(array $change): string
181
169
182
170
$ html .=
183
171
'<tr> ' .
184
- ($ this ->options ['lineNumbers ' ] ?
185
- '<th class="n-old"> ' . $ oldLineNum . '</th> '
186
- : ''
187
- ) .
172
+ $ this ->renderLineNumberColumn ('old ' , $ oldLineNum ) .
188
173
'<td class="old"> ' . $ oldLine . '</td> ' .
189
- ($ this ->options ['lineNumbers ' ] ?
190
- '<th></th> '
191
- : ''
192
- ) .
174
+ $ this ->renderLineNumberColumn ('' , null ) .
193
175
'<td class="new"></td> ' .
194
176
'</tr> ' ;
195
177
}
@@ -220,15 +202,9 @@ protected function renderTableReplace(array $change): string
220
202
221
203
$ html .=
222
204
'<tr> ' .
223
- ($ this ->options ['lineNumbers ' ] ?
224
- '<th class="n-old"> ' . $ oldLineNum . '</th> '
225
- : ''
226
- ) .
205
+ $ this ->renderLineNumberColumn ('old ' , $ oldLineNum ) .
227
206
'<td class="old"><span> ' . $ oldLine . '</span></td> ' .
228
- ($ this ->options ['lineNumbers ' ] ?
229
- '<th class="n-new"> ' . $ newLineNum . '</th> '
230
- : ''
231
- ) .
207
+ $ this ->renderLineNumberColumn ('new ' , $ oldLineNum ) .
232
208
'<td class="new"> ' . $ newLine . '</td> ' .
233
209
'</tr> ' ;
234
210
}
@@ -246,20 +222,31 @@ protected function renderTableReplace(array $change): string
246
222
247
223
$ html .=
248
224
'<tr> ' .
249
- ($ this ->options ['lineNumbers ' ] ?
250
- '<th class="n-old"> ' . $ oldLineNum . '</th> '
251
- : ''
252
- ) .
225
+ $ this ->renderLineNumberColumn ('old ' , $ oldLineNum ) .
253
226
'<td class="old"><span> ' . $ oldLine . '</span></td> ' .
254
- ($ this ->options ['lineNumbers ' ] ?
255
- '<th class="n-new"> ' . $ newLineNum . '</th> '
256
- : ''
257
- ) .
227
+ $ this ->renderLineNumberColumn ('new ' , $ newLineNum ) .
258
228
'<td class="new"> ' . $ newLine . '</td> ' .
259
229
'</tr> ' ;
260
230
}
261
231
}
262
232
263
233
return $ html ;
264
234
}
235
+
236
+ /**
237
+ * Renderer the line number column.
238
+ *
239
+ * @param string $type The diff type
240
+ * @param null|int $lineNum The line number
241
+ */
242
+ protected function renderLineNumberColumn (string $ type , ?int $ lineNum ): string
243
+ {
244
+ if (!$ this ->options ['lineNumbers ' ]) {
245
+ return '' ;
246
+ }
247
+
248
+ return isset ($ lineNum )
249
+ ? '<th class="n- ' . $ type . '"> ' . $ lineNum . '</th> '
250
+ : '<th></th> ' ;
251
+ }
265
252
}
0 commit comments