@@ -33,21 +33,11 @@ protected function redererChanges(array $changes): string
33
33
['diff ' , 'diff-html ' , 'diff-inline ' ]
34
34
);
35
35
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> ' ;
51
41
}
52
42
53
43
/**
@@ -89,49 +79,71 @@ protected function renderTableSeparateBlock(): string
89
79
'</tbody> ' ;
90
80
}
91
81
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
+
92
104
/**
93
105
* Renderer the table block.
94
106
*
95
- * @param array $change the change
107
+ * @param array $block the block
96
108
*/
97
- protected function renderTableBlock (array $ change ): string
109
+ protected function renderTableBlock (array $ block ): string
98
110
{
99
111
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 ' ,
104
116
];
105
117
106
118
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 ) .
109
121
'</tbody> ' ;
110
122
}
111
123
112
124
/**
113
125
* Renderer the table block: equal.
114
126
*
115
- * @param array $change the change
127
+ * @param array $block the block
116
128
*/
117
- protected function renderTableEqual (array $ change ): string
129
+ protected function renderTableBlockEqual (array $ block ): string
118
130
{
119
131
$ html = '' ;
120
132
121
133
// note that although we are in a OP_EQ situation,
122
134
// the old and the new may not be exactly the same
123
135
// 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 ;
129
141
130
142
$ html .=
131
143
'<tr data-type="="> ' .
132
144
$ this ->renderLineNumberColumns ($ oldLineNum , $ newLineNum ) .
133
145
'<th class="sign"></th> ' .
134
- '<td class="old "> ' . $ oldLine . '</td> ' .
146
+ '<td class="new "> ' . $ newLine . '</td> ' .
135
147
'</tr> ' ;
136
148
}
137
149
@@ -141,14 +153,14 @@ protected function renderTableEqual(array $change): string
141
153
/**
142
154
* Renderer the table block: insert.
143
155
*
144
- * @param array $change the change
156
+ * @param array $block the block
145
157
*/
146
- protected function renderTableInsert (array $ change ): string
158
+ protected function renderTableBlockInsert (array $ block ): string
147
159
{
148
160
$ html = '' ;
149
161
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 ;
152
164
153
165
$ html .=
154
166
'<tr data-type="+"> ' .
@@ -164,14 +176,14 @@ protected function renderTableInsert(array $change): string
164
176
/**
165
177
* Renderer the table block: delete.
166
178
*
167
- * @param array $change the change
179
+ * @param array $block the block
168
180
*/
169
- protected function renderTableDelete (array $ change ): string
181
+ protected function renderTableBlockDelete (array $ block ): string
170
182
{
171
183
$ html = '' ;
172
184
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 ;
175
187
176
188
$ html .=
177
189
'<tr data-type="-"> ' .
@@ -187,14 +199,14 @@ protected function renderTableDelete(array $change): string
187
199
/**
188
200
* Renderer the table block: replace.
189
201
*
190
- * @param array $change the change
202
+ * @param array $block the block
191
203
*/
192
- protected function renderTableReplace (array $ change ): string
204
+ protected function renderTableBlockReplace (array $ block ): string
193
205
{
194
206
$ html = '' ;
195
207
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 ;
198
210
199
211
$ html .=
200
212
'<tr data-type="-"> ' .
@@ -204,8 +216,8 @@ protected function renderTableReplace(array $change): string
204
216
'</tr> ' ;
205
217
}
206
218
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 ;
209
221
210
222
$ html .=
211
223
'<tr data-type="+"> ' .
0 commit comments