@@ -33,21 +33,11 @@ protected function redererChanges(array $changes): string
3333 ['diff ' , 'diff-html ' , 'diff-inline ' ]
3434 );
3535
36- $ html = '<table class=" ' . \implode (' ' , $ wrapperClasses ) . '"> ' ;
37-
38- $ html .= $ this ->renderTableHeader ();
39-
40- foreach ($ changes as $ i => $ blocks ) {
41- if ($ i > 0 && $ this ->options ['separateBlock ' ]) {
42- $ html .= $ this ->renderTableSeparateBlock ();
43- }
44-
45- foreach ($ blocks as $ change ) {
46- $ html .= $ this ->renderTableBlock ($ change );
47- }
48- }
49-
50- return $ html . '</table> ' ;
36+ return
37+ '<table class=" ' . \implode (' ' , $ wrapperClasses ) . '"> ' .
38+ $ this ->renderTableHeader () .
39+ $ this ->renderTableHunks ($ changes ) .
40+ '</table> ' ;
5141 }
5242
5343 /**
@@ -89,49 +79,71 @@ protected function renderTableSeparateBlock(): string
8979 '</tbody> ' ;
9080 }
9181
82+ /**
83+ * Renderer table hunks.
84+ *
85+ * @param array $hunks each hunk has many blocks
86+ */
87+ protected function renderTableHunks (array $ hunks ): string
88+ {
89+ $ html = '' ;
90+
91+ foreach ($ hunks as $ i => $ hunk ) {
92+ if ($ i > 0 && $ this ->options ['separateBlock ' ]) {
93+ $ html .= $ this ->renderTableSeparateBlock ();
94+ }
95+
96+ foreach ($ hunk as $ block ) {
97+ $ html .= $ this ->renderTableBlock ($ block );
98+ }
99+ }
100+
101+ return $ html ;
102+ }
103+
92104 /**
93105 * Renderer the table block.
94106 *
95- * @param array $change the change
107+ * @param array $block the block
96108 */
97- protected function renderTableBlock (array $ change ): string
109+ protected function renderTableBlock (array $ block ): string
98110 {
99111 static $ callbacks = [
100- SequenceMatcher::OP_EQ => 'renderTableEqual ' ,
101- SequenceMatcher::OP_INS => 'renderTableInsert ' ,
102- SequenceMatcher::OP_DEL => 'renderTableDelete ' ,
103- SequenceMatcher::OP_REP => 'renderTableReplace ' ,
112+ SequenceMatcher::OP_EQ => 'renderTableBlockEqual ' ,
113+ SequenceMatcher::OP_INS => 'renderTableBlockInsert ' ,
114+ SequenceMatcher::OP_DEL => 'renderTableBlockDelete ' ,
115+ SequenceMatcher::OP_REP => 'renderTableBlockReplace ' ,
104116 ];
105117
106118 return
107- '<tbody class="change change- ' . self ::TAG_CLASS_MAP [$ change ['tag ' ]] . '"> ' .
108- $ this ->{$ callbacks [$ change ['tag ' ]]}($ change ) .
119+ '<tbody class="change change- ' . self ::TAG_CLASS_MAP [$ block ['tag ' ]] . '"> ' .
120+ $ this ->{$ callbacks [$ block ['tag ' ]]}($ block ) .
109121 '</tbody> ' ;
110122 }
111123
112124 /**
113125 * Renderer the table block: equal.
114126 *
115- * @param array $change the change
127+ * @param array $block the block
116128 */
117- protected function renderTableEqual (array $ change ): string
129+ protected function renderTableBlockEqual (array $ block ): string
118130 {
119131 $ html = '' ;
120132
121133 // note that although we are in a OP_EQ situation,
122134 // the old and the new may not be exactly the same
123135 // because of ignoreCase, ignoreWhitespace, etc
124- foreach ($ change [ ' old ' ]['lines ' ] as $ no => $ oldLine ) {
125- // hmm... but this is a inline renderer
126- // we could only pick a line from the old or the new to show
127- $ oldLineNum = $ change ['old ' ]['offset ' ] + $ no + 1 ;
128- $ newLineNum = $ change ['new ' ]['offset ' ] + $ no + 1 ;
136+ foreach ($ block [ ' new ' ]['lines ' ] as $ no => $ newLine ) {
137+ // hmm... but there is only space for one line
138+ // we could only pick either the old or the new to show
139+ $ oldLineNum = $ block ['old ' ]['offset ' ] + $ no + 1 ;
140+ $ newLineNum = $ block ['new ' ]['offset ' ] + $ no + 1 ;
129141
130142 $ html .=
131143 '<tr data-type="="> ' .
132144 $ this ->renderLineNumberColumns ($ oldLineNum , $ newLineNum ) .
133145 '<th class="sign"></th> ' .
134- '<td class="old "> ' . $ oldLine . '</td> ' .
146+ '<td class="new "> ' . $ newLine . '</td> ' .
135147 '</tr> ' ;
136148 }
137149
@@ -141,14 +153,14 @@ protected function renderTableEqual(array $change): string
141153 /**
142154 * Renderer the table block: insert.
143155 *
144- * @param array $change the change
156+ * @param array $block the block
145157 */
146- protected function renderTableInsert (array $ change ): string
158+ protected function renderTableBlockInsert (array $ block ): string
147159 {
148160 $ html = '' ;
149161
150- foreach ($ change ['new ' ]['lines ' ] as $ no => $ newLine ) {
151- $ newLineNum = $ change ['new ' ]['offset ' ] + $ no + 1 ;
162+ foreach ($ block ['new ' ]['lines ' ] as $ no => $ newLine ) {
163+ $ newLineNum = $ block ['new ' ]['offset ' ] + $ no + 1 ;
152164
153165 $ html .=
154166 '<tr data-type="+"> ' .
@@ -164,14 +176,14 @@ protected function renderTableInsert(array $change): string
164176 /**
165177 * Renderer the table block: delete.
166178 *
167- * @param array $change the change
179+ * @param array $block the block
168180 */
169- protected function renderTableDelete (array $ change ): string
181+ protected function renderTableBlockDelete (array $ block ): string
170182 {
171183 $ html = '' ;
172184
173- foreach ($ change ['old ' ]['lines ' ] as $ no => $ oldLine ) {
174- $ oldLineNum = $ change ['old ' ]['offset ' ] + $ no + 1 ;
185+ foreach ($ block ['old ' ]['lines ' ] as $ no => $ oldLine ) {
186+ $ oldLineNum = $ block ['old ' ]['offset ' ] + $ no + 1 ;
175187
176188 $ html .=
177189 '<tr data-type="-"> ' .
@@ -187,14 +199,14 @@ protected function renderTableDelete(array $change): string
187199 /**
188200 * Renderer the table block: replace.
189201 *
190- * @param array $change the change
202+ * @param array $block the block
191203 */
192- protected function renderTableReplace (array $ change ): string
204+ protected function renderTableBlockReplace (array $ block ): string
193205 {
194206 $ html = '' ;
195207
196- foreach ($ change ['old ' ]['lines ' ] as $ no => $ oldLine ) {
197- $ oldLineNum = $ change ['old ' ]['offset ' ] + $ no + 1 ;
208+ foreach ($ block ['old ' ]['lines ' ] as $ no => $ oldLine ) {
209+ $ oldLineNum = $ block ['old ' ]['offset ' ] + $ no + 1 ;
198210
199211 $ html .=
200212 '<tr data-type="-"> ' .
@@ -204,8 +216,8 @@ protected function renderTableReplace(array $change): string
204216 '</tr> ' ;
205217 }
206218
207- foreach ($ change ['new ' ]['lines ' ] as $ no => $ newLine ) {
208- $ newLineNum = $ change ['new ' ]['offset ' ] + $ no + 1 ;
219+ foreach ($ block ['new ' ]['lines ' ] as $ no => $ newLine ) {
220+ $ newLineNum = $ block ['new ' ]['offset ' ] + $ no + 1 ;
209221
210222 $ html .=
211223 '<tr data-type="+"> ' .
0 commit comments