File tree Expand file tree Collapse file tree 6 files changed +66
-89
lines changed Expand file tree Collapse file tree 6 files changed +66
-89
lines changed Original file line number Diff line number Diff line change @@ -154,24 +154,13 @@ final public function renderArray(array $differArray): string
154
154
* @param Differ $differ the differ object
155
155
*/
156
156
abstract protected function renderWoker (Differ $ differ ): string ;
157
-
157
+
158
158
/**
159
- * The worker for array render .
159
+ * The real worker for self::renderArray() .
160
160
*
161
161
* @param array $differArray the differ array
162
- *
163
- * @return string
164
162
*/
165
163
abstract protected function renderArrayWoker (array $ differArray ): string ;
166
-
167
- /**
168
- * Woker's base function.
169
- *
170
- * @param array $changes the changes array
171
- *
172
- * @return string
173
- */
174
- abstract protected function baseWoker (array $ changes ): string ;
175
164
176
165
/**
177
166
* Update the Language object.
Original file line number Diff line number Diff line change @@ -127,6 +127,29 @@ public function getChanges(Differ $differ): array
127
127
return $ changes ;
128
128
}
129
129
130
+ /**
131
+ * {@inheritdoc}
132
+ */
133
+ protected function renderWoker (Differ $ differ ): string
134
+ {
135
+ return $ this ->redererChanges ($ this ->getChanges ($ differ ));
136
+ }
137
+
138
+ /**
139
+ * {@inheritdoc}
140
+ */
141
+ protected function renderArrayWoker (array $ differArray ): string
142
+ {
143
+ return $ this ->redererChanges ($ this ->ensureChangesUseIntTag ($ differArray ));
144
+ }
145
+
146
+ /**
147
+ * Render the array of changes.
148
+ *
149
+ * @param array $changes the changes
150
+ */
151
+ abstract protected function redererChanges (array $ changes ): string ;
152
+
130
153
/**
131
154
* Renderer the changed extent.
132
155
*
@@ -284,4 +307,40 @@ function (array $matches): string {
284
307
$ string
285
308
);
286
309
}
310
+
311
+ /**
312
+ * Make sure the "changes" array uses int "tag".
313
+ *
314
+ * Internally, we would like always int form for better performance.
315
+ *
316
+ * @param array $changes the changes
317
+ */
318
+ protected function ensureChangesUseIntTag (array $ changes ): array
319
+ {
320
+ if (empty ($ changes )) {
321
+ return [];
322
+ }
323
+
324
+ $ isTagInt = true ;
325
+ foreach ($ changes as $ blocks ) {
326
+ foreach ($ blocks as $ change ) {
327
+ $ isTagInt = \is_int ($ change ['tag ' ]);
328
+
329
+ break 2 ;
330
+ }
331
+ }
332
+
333
+ if (!$ isTagInt ) {
334
+ // convert string tags into their int forms
335
+ foreach ($ changes as &$ blocks ) {
336
+ foreach ($ blocks as &$ change ) {
337
+ $ change ['tag ' ] = SequenceMatcher::opStrToInt ($ change ['tag ' ]);
338
+ }
339
+ }
340
+
341
+ unset($ blocks , $ change );
342
+ }
343
+
344
+ return $ changes ;
345
+ }
287
346
}
Original file line number Diff line number Diff line change 4
4
5
5
namespace Jfcherng \Diff \Renderer \Html ;
6
6
7
- use Jfcherng \Diff \Differ ;
8
7
use Jfcherng \Diff \SequenceMatcher ;
9
8
10
9
/**
@@ -23,32 +22,12 @@ final class Inline extends AbstractHtml
23
22
/**
24
23
* {@inheritdoc}
25
24
*/
26
- protected function renderWoker (Differ $ differ ): string
27
- {
28
- $ changes = $ this ->getChanges ($ differ );
29
-
30
- return $ this ->baseWoker ($ changes );
31
- }
32
-
33
- /**
34
- * {@inheritdoc}
35
- */
36
- protected function renderArrayWoker (array $ differArray ): string
37
- {
38
- $ changes = $ differArray ;
39
-
40
- return $ this ->baseWoker ($ changes );
41
- }
42
-
43
- /**
44
- * {@inheritdoc}
45
- */
46
- protected function baseWoker (array $ changes ): string
25
+ protected function redererChanges (array $ changes ): string
47
26
{
48
27
if (empty ($ changes )) {
49
28
return $ this ->getResultForIdenticals ();
50
29
}
51
-
30
+
52
31
$ wrapperClasses = \array_merge (
53
32
$ this ->options ['wrapperClasses ' ],
54
33
['diff ' , 'diff-html ' , 'diff-inline ' ]
Original file line number Diff line number Diff line change 4
4
5
5
namespace Jfcherng \Diff \Renderer \Html ;
6
6
7
- use Jfcherng \Diff \Differ ;
8
7
use Jfcherng \Diff \SequenceMatcher ;
9
8
10
9
/**
@@ -36,10 +35,8 @@ public function getResultForIdenticalsDefault(): string
36
35
/**
37
36
* {@inheritdoc}
38
37
*/
39
- protected function renderWoker ( Differ $ differ ): string
38
+ protected function redererChanges ( array $ changes ): string
40
39
{
41
- $ changes = $ this ->getChanges ($ differ );
42
-
43
40
if ($ this ->options ['outputTagAsString ' ]) {
44
41
$ this ->convertTagToString ($ changes );
45
42
}
@@ -50,22 +47,6 @@ protected function renderWoker(Differ $differ): string
50
47
);
51
48
}
52
49
53
- /**
54
- * {@inheritdoc}
55
- */
56
- public function renderArrayWoker (array $ differArray ): string
57
- {
58
- return '' ;
59
- }
60
-
61
- /**
62
- * {@inheritdoc}
63
- */
64
- public function baseWoker (array $ changes ): string
65
- {
66
- return '' ;
67
- }
68
-
69
50
/**
70
51
* Convert tags of changes to their string form for better readability.
71
52
*
Original file line number Diff line number Diff line change 4
4
5
5
namespace Jfcherng \Diff \Renderer \Html ;
6
6
7
- use Jfcherng \Diff \Differ ;
8
7
use Jfcherng \Diff \SequenceMatcher ;
9
8
10
9
/**
@@ -23,27 +22,7 @@ final class SideBySide extends AbstractHtml
23
22
/**
24
23
* {@inheritdoc}
25
24
*/
26
- protected function renderWoker (Differ $ differ ): string
27
- {
28
- $ changes = $ this ->getChanges ($ differ );
29
-
30
- return $ this ->baseWoker ($ changes );
31
- }
32
-
33
- /**
34
- * {@inheritdoc}
35
- */
36
- protected function renderArrayWoker (array $ differArray ): string
37
- {
38
- $ changes = $ differArray ;
39
-
40
- return $ this ->baseWoker ($ changes );
41
- }
42
-
43
- /**
44
- * {@inheritdoc}
45
- */
46
- protected function baseWoker (array $ changes ): string
25
+ protected function redererChanges (array $ changes ): string
47
26
{
48
27
if (empty ($ changes )) {
49
28
return $ this ->getResultForIdenticals ();
Original file line number Diff line number Diff line change @@ -32,16 +32,6 @@ public function renderArrayWoker(array $differArray): string
32
32
{
33
33
throw new UnsupportedFunctionException (__METHOD__ );
34
34
35
- return '' ;
36
- }
37
-
38
- /**
39
- * {@inheritdoc}
40
- */
41
- public function baseWoker (array $ changes ): string
42
- {
43
- throw new UnsupportedFunctionException (__METHOD__ );
44
-
45
- return '' ;
35
+ return '' ; // make IDE not complain
46
36
}
47
37
}
You can’t perform that action at this time.
0 commit comments