@@ -122,10 +122,12 @@ protected function renderTableBlockEqual(array $block): string
122
122
{
123
123
$ ret = '' ;
124
124
125
- foreach ($ block ['new ' ]['lines ' ] as $ no => $ newLine ) {
125
+ $ rowCount = \count ($ block ['new ' ]['lines ' ]);
126
+
127
+ for ($ no = 0 ; $ no < $ rowCount ; ++$ no ) {
126
128
$ ret .= $ this ->renderTableRow (
127
- $ block ['old ' ]['lines ' ][$ no ], // $oldLine
128
- $ newLine ,
129
+ $ block ['old ' ]['lines ' ][$ no ],
130
+ $ block [ ' new ' ][ ' lines ' ][ $ no ] ,
129
131
$ block ['old ' ]['offset ' ] + $ no + 1 ,
130
132
$ block ['new ' ]['offset ' ] + $ no + 1
131
133
);
@@ -145,7 +147,7 @@ protected function renderTableBlockInsert(array $block): string
145
147
146
148
foreach ($ block ['new ' ]['lines ' ] as $ no => $ newLine ) {
147
149
$ ret .= $ this ->renderTableRow (
148
- '' ,
150
+ null ,
149
151
$ newLine ,
150
152
null ,
151
153
$ block ['new ' ]['offset ' ] + $ no + 1
@@ -167,7 +169,7 @@ protected function renderTableBlockDelete(array $block): string
167
169
foreach ($ block ['old ' ]['lines ' ] as $ no => $ oldLine ) {
168
170
$ ret .= $ this ->renderTableRow (
169
171
$ oldLine ,
170
- '' ,
172
+ null ,
171
173
$ block ['old ' ]['offset ' ] + $ no + 1 ,
172
174
null
173
175
);
@@ -192,16 +194,14 @@ protected function renderTableBlockReplace(array $block): string
192
194
$ oldLineNum = $ block ['old ' ]['offset ' ] + $ no + 1 ;
193
195
$ oldLine = $ block ['old ' ]['lines ' ][$ no ];
194
196
} else {
195
- $ oldLineNum = null ;
196
- $ oldLine = '' ;
197
+ $ oldLineNum = $ oldLine = null ;
197
198
}
198
199
199
200
if (isset ($ block ['new ' ]['lines ' ][$ no ])) {
200
201
$ newLineNum = $ block ['new ' ]['offset ' ] + $ no + 1 ;
201
202
$ newLine = $ block ['new ' ]['lines ' ][$ no ];
202
203
} else {
203
- $ newLineNum = null ;
204
- $ newLine = '' ;
204
+ $ newLineNum = $ newLine = null ;
205
205
}
206
206
207
207
$ ret .= $ this ->renderTableRow ($ oldLine , $ newLine , $ oldLineNum , $ newLineNum );
@@ -213,47 +213,58 @@ protected function renderTableBlockReplace(array $block): string
213
213
/**
214
214
* Renderer a content row of the output table.
215
215
*
216
- * @param string $oldLine the old line
217
- * @param string $newLine the new line
218
- * @param null|int $oldLineNum the old line number
219
- * @param null|int $newLineNum the new line number
216
+ * @param null| string $oldLine the old line
217
+ * @param null| string $newLine the new line
218
+ * @param null|int $oldLineNum the old line number
219
+ * @param null|int $newLineNum the new line number
220
220
*/
221
221
protected function renderTableRow (
222
- string $ oldLine ,
223
- string $ newLine ,
222
+ ? string $ oldLine ,
223
+ ? string $ newLine ,
224
224
?int $ oldLineNum ,
225
225
?int $ newLineNum
226
226
): string {
227
- $ hasOldLineNum = isset ($ oldLineNum );
228
- $ hasNewLineNum = isset ($ newLineNum );
229
-
230
227
return
231
228
'<tr> ' .
232
229
(
233
230
$ this ->options ['lineNumbers ' ]
234
- ? $ this ->renderLineNumberColumn ($ hasOldLineNum ? 'old ' : ' ' , $ oldLineNum )
231
+ ? $ this ->renderLineNumberColumn ('old ' , $ oldLineNum )
235
232
: ''
236
233
) .
237
- ' <td class=" old ' . ( $ hasOldLineNum ? '' : ' none ' ) . ' "> ' . $ oldLine . ' </td> ' .
234
+ $ this -> renderLineContentColumn ( ' old ', $ oldLine) .
238
235
(
239
236
$ this ->options ['lineNumbers ' ]
240
- ? $ this ->renderLineNumberColumn ($ hasNewLineNum ? 'new ' : ' ' , $ newLineNum )
237
+ ? $ this ->renderLineNumberColumn ('new ' , $ newLineNum )
241
238
: ''
242
239
) .
243
- ' <td class=" new ' . ( $ hasNewLineNum ? '' : ' none ' ) . ' "> ' . $ newLine . ' </td> ' .
240
+ $ this -> renderLineContentColumn ( ' new ', $ newLine) .
244
241
'</tr> ' ;
245
242
}
246
243
247
244
/**
248
245
* Renderer the line number column.
249
246
*
250
- * @param string $type The diff type
251
- * @param null|int $lineNum The line number
247
+ * @param string $type the diff type
248
+ * @param null|int $lineNum the line number
252
249
*/
253
250
protected function renderLineNumberColumn (string $ type , ?int $ lineNum ): string
254
251
{
255
252
return isset ($ lineNum )
256
253
? '<th class="n- ' . $ type . '"> ' . $ lineNum . '</th> '
257
254
: '<th></th> ' ;
258
255
}
256
+
257
+ /**
258
+ * Renderer the line content column.
259
+ *
260
+ * @param string $type the diff type
261
+ * @param null|string $content the line content
262
+ */
263
+ protected function renderLineContentColumn (string $ type , ?string $ content ): string
264
+ {
265
+ return
266
+ '<td class=" ' . $ type . (isset ($ content ) ? '' : ' none ' ) . '"> ' .
267
+ $ content .
268
+ '</td> ' ;
269
+ }
259
270
}
0 commit comments