@@ -122,10 +122,12 @@ protected function renderTableBlockEqual(array $block): string
122122 {
123123 $ ret = '' ;
124124
125- foreach ($ block ['new ' ]['lines ' ] as $ no => $ newLine ) {
125+ $ rowCount = \count ($ block ['new ' ]['lines ' ]);
126+
127+ for ($ no = 0 ; $ no < $ rowCount ; ++$ no ) {
126128 $ ret .= $ this ->renderTableRow (
127- $ block ['old ' ]['lines ' ][$ no ], // $oldLine
128- $ newLine ,
129+ $ block ['old ' ]['lines ' ][$ no ],
130+ $ block [ ' new ' ][ ' lines ' ][ $ no ] ,
129131 $ block ['old ' ]['offset ' ] + $ no + 1 ,
130132 $ block ['new ' ]['offset ' ] + $ no + 1
131133 );
@@ -145,7 +147,7 @@ protected function renderTableBlockInsert(array $block): string
145147
146148 foreach ($ block ['new ' ]['lines ' ] as $ no => $ newLine ) {
147149 $ ret .= $ this ->renderTableRow (
148- '' ,
150+ null ,
149151 $ newLine ,
150152 null ,
151153 $ block ['new ' ]['offset ' ] + $ no + 1
@@ -167,7 +169,7 @@ protected function renderTableBlockDelete(array $block): string
167169 foreach ($ block ['old ' ]['lines ' ] as $ no => $ oldLine ) {
168170 $ ret .= $ this ->renderTableRow (
169171 $ oldLine ,
170- '' ,
172+ null ,
171173 $ block ['old ' ]['offset ' ] + $ no + 1 ,
172174 null
173175 );
@@ -192,16 +194,14 @@ protected function renderTableBlockReplace(array $block): string
192194 $ oldLineNum = $ block ['old ' ]['offset ' ] + $ no + 1 ;
193195 $ oldLine = $ block ['old ' ]['lines ' ][$ no ];
194196 } else {
195- $ oldLineNum = null ;
196- $ oldLine = '' ;
197+ $ oldLineNum = $ oldLine = null ;
197198 }
198199
199200 if (isset ($ block ['new ' ]['lines ' ][$ no ])) {
200201 $ newLineNum = $ block ['new ' ]['offset ' ] + $ no + 1 ;
201202 $ newLine = $ block ['new ' ]['lines ' ][$ no ];
202203 } else {
203- $ newLineNum = null ;
204- $ newLine = '' ;
204+ $ newLineNum = $ newLine = null ;
205205 }
206206
207207 $ ret .= $ this ->renderTableRow ($ oldLine , $ newLine , $ oldLineNum , $ newLineNum );
@@ -213,47 +213,58 @@ protected function renderTableBlockReplace(array $block): string
213213 /**
214214 * Renderer a content row of the output table.
215215 *
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
220220 */
221221 protected function renderTableRow (
222- string $ oldLine ,
223- string $ newLine ,
222+ ? string $ oldLine ,
223+ ? string $ newLine ,
224224 ?int $ oldLineNum ,
225225 ?int $ newLineNum
226226 ): string {
227- $ hasOldLineNum = isset ($ oldLineNum );
228- $ hasNewLineNum = isset ($ newLineNum );
229-
230227 return
231228 '<tr> ' .
232229 (
233230 $ this ->options ['lineNumbers ' ]
234- ? $ this ->renderLineNumberColumn ($ hasOldLineNum ? 'old ' : ' ' , $ oldLineNum )
231+ ? $ this ->renderLineNumberColumn ('old ' , $ oldLineNum )
235232 : ''
236233 ) .
237- ' <td class=" old ' . ( $ hasOldLineNum ? '' : ' none ' ) . ' "> ' . $ oldLine . ' </td> ' .
234+ $ this -> renderLineContentColumn ( ' old ', $ oldLine) .
238235 (
239236 $ this ->options ['lineNumbers ' ]
240- ? $ this ->renderLineNumberColumn ($ hasNewLineNum ? 'new ' : ' ' , $ newLineNum )
237+ ? $ this ->renderLineNumberColumn ('new ' , $ newLineNum )
241238 : ''
242239 ) .
243- ' <td class=" new ' . ( $ hasNewLineNum ? '' : ' none ' ) . ' "> ' . $ newLine . ' </td> ' .
240+ $ this -> renderLineContentColumn ( ' new ', $ newLine) .
244241 '</tr> ' ;
245242 }
246243
247244 /**
248245 * Renderer the line number column.
249246 *
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
252249 */
253250 protected function renderLineNumberColumn (string $ type , ?int $ lineNum ): string
254251 {
255252 return isset ($ lineNum )
256253 ? '<th class="n- ' . $ type . '"> ' . $ lineNum . '</th> '
257254 : '<th></th> ' ;
258255 }
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+ }
259270}
0 commit comments