@@ -55,7 +55,7 @@ protected function redererChanges(array $changes): string
5555 */
5656 protected function renderTableHeader (): string
5757 {
58- $ colspan = ( $ this ->options ['lineNumbers ' ] ? ' colspan="2" ' : '' ) ;
58+ $ colspan = $ this ->options ['lineNumbers ' ] ? ' colspan="2" ' : '' ;
5959
6060 return
6161 '<thead> ' .
@@ -71,7 +71,7 @@ protected function renderTableHeader(): string
7171 */
7272 protected function renderTableSeparateBlock (): string
7373 {
74- $ colspan = (! $ this ->options ['lineNumbers ' ] ? '2 ' : '4 ' ) ;
74+ $ colspan = $ this ->options ['lineNumbers ' ] ? '4 ' : '2 ' ;
7575
7676 return
7777 '<tbody class="skipped"> ' .
@@ -121,15 +121,9 @@ protected function renderTableEqual(array $change): string
121121
122122 $ html .=
123123 '<tr> ' .
124- ($ this ->options ['lineNumbers ' ] ?
125- '<th class="n-old"> ' . $ oldLineNum . '</th> '
126- : ''
127- ) .
124+ $ this ->renderLineNumberColumn ('old ' , $ oldLineNum ) .
128125 '<td class="old"> ' . $ oldLine . '</td> ' .
129- ($ this ->options ['lineNumbers ' ] ?
130- '<th class="n-new"> ' . $ newLineNum . '</th> '
131- : ''
132- ) .
126+ $ this ->renderLineNumberColumn ('new ' , $ newLineNum ) .
133127 '<td class="new"> ' . $ newLine . '</td> ' .
134128 '</tr> ' ;
135129 }
@@ -151,15 +145,9 @@ protected function renderTableInsert(array $change): string
151145
152146 $ html .=
153147 '<tr> ' .
154- ($ this ->options ['lineNumbers ' ] ?
155- '<th></th> '
156- : ''
157- ) .
148+ $ this ->renderLineNumberColumn ('' , null ) .
158149 '<td class="old"></td> ' .
159- ($ this ->options ['lineNumbers ' ] ?
160- '<th class="n-new"> ' . $ newLineNum . '</th> '
161- : ''
162- ) .
150+ $ this ->renderLineNumberColumn ('new ' , $ newLineNum ) .
163151 '<td class="new"> ' . $ newLine . '</td> ' .
164152 '</tr> ' ;
165153 }
@@ -181,15 +169,9 @@ protected function renderTableDelete(array $change): string
181169
182170 $ html .=
183171 '<tr> ' .
184- ($ this ->options ['lineNumbers ' ] ?
185- '<th class="n-old"> ' . $ oldLineNum . '</th> '
186- : ''
187- ) .
172+ $ this ->renderLineNumberColumn ('old ' , $ oldLineNum ) .
188173 '<td class="old"> ' . $ oldLine . '</td> ' .
189- ($ this ->options ['lineNumbers ' ] ?
190- '<th></th> '
191- : ''
192- ) .
174+ $ this ->renderLineNumberColumn ('' , null ) .
193175 '<td class="new"></td> ' .
194176 '</tr> ' ;
195177 }
@@ -220,15 +202,9 @@ protected function renderTableReplace(array $change): string
220202
221203 $ html .=
222204 '<tr> ' .
223- ($ this ->options ['lineNumbers ' ] ?
224- '<th class="n-old"> ' . $ oldLineNum . '</th> '
225- : ''
226- ) .
205+ $ this ->renderLineNumberColumn ('old ' , $ oldLineNum ) .
227206 '<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 ) .
232208 '<td class="new"> ' . $ newLine . '</td> ' .
233209 '</tr> ' ;
234210 }
@@ -246,20 +222,31 @@ protected function renderTableReplace(array $change): string
246222
247223 $ html .=
248224 '<tr> ' .
249- ($ this ->options ['lineNumbers ' ] ?
250- '<th class="n-old"> ' . $ oldLineNum . '</th> '
251- : ''
252- ) .
225+ $ this ->renderLineNumberColumn ('old ' , $ oldLineNum ) .
253226 '<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 ) .
258228 '<td class="new"> ' . $ newLine . '</td> ' .
259229 '</tr> ' ;
260230 }
261231 }
262232
263233 return $ html ;
264234 }
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+ }
265252}
0 commit comments