@@ -70,12 +70,11 @@ public function getChanges(Differ $differ): array
70
70
$ lastBlock = 0 ;
71
71
72
72
foreach ($ opcodes as [$ op , $ i1 , $ i2 , $ j1 , $ j2 ]) {
73
- if (
74
- $ op === SequenceMatcher::OP_REP &&
75
- $ i2 - $ i1 === $ j2 - $ j1
76
- ) {
77
- for ($ i = 0 ; $ i < $ i2 - $ i1 ; ++$ i ) {
78
- $ this ->renderChangedExtent ($ lineRenderer , $ old [$ i1 + $ i ], $ new [$ j1 + $ i ]);
73
+ // if there are same amount of lines replaced
74
+ // we can render the inner detailed changes with corresponding lines
75
+ if ($ op === SequenceMatcher::OP_REP && $ i2 - $ i1 === $ j2 - $ j1 ) {
76
+ for ($ k = 0 ; $ k < $ i2 - $ i1 ; ++$ k ) {
77
+ $ this ->renderChangedExtent ($ lineRenderer , $ old [$ i1 + $ k ], $ new [$ j1 + $ k ]);
79
78
}
80
79
}
81
80
@@ -142,13 +141,17 @@ protected function renderWorker(Differ $differ): string
142
141
*/
143
142
protected function renderArrayWorker (array $ differArray ): string
144
143
{
145
- return $ this ->redererChanges ($ this ->ensureChangesUseIntTag ($ differArray ));
144
+ $ this ->ensureChangesUseIntTag ($ differArray );
145
+
146
+ return $ this ->redererChanges ($ differArray );
146
147
}
147
148
148
149
/**
149
150
* Render the array of changes.
150
151
*
151
152
* @param array $changes the changes
153
+ *
154
+ * @todo rename typo to renderChanges() in v7
152
155
*/
153
156
abstract protected function redererChanges (array $ changes ): string ;
154
157
@@ -159,8 +162,6 @@ abstract protected function redererChanges(array $changes): string;
159
162
* @param string $old the old line
160
163
* @param string $new the new line
161
164
*
162
- * @throws \InvalidArgumentException
163
- *
164
165
* @return static
165
166
*/
166
167
protected function renderChangedExtent (AbstractLineRenderer $ lineRenderer , string &$ old , string &$ new ): self
@@ -321,32 +322,17 @@ function (array $matches): string {
321
322
*
322
323
* @param array $changes the changes
323
324
*/
324
- protected function ensureChangesUseIntTag (array $ changes ): array
325
+ protected function ensureChangesUseIntTag (array & $ changes ): void
325
326
{
326
- if (empty ($ changes )) {
327
- return [];
328
- }
329
-
330
- $ isTagInt = true ;
331
- foreach ($ changes as $ blocks ) {
332
- foreach ($ blocks as $ change ) {
333
- $ isTagInt = \is_int ($ change ['tag ' ]);
334
-
335
- break 2 ;
336
- }
327
+ // check if the tag is already int type
328
+ if (\is_int ($ changes [0 ][0 ]['tag ' ] ?? null )) {
329
+ return ;
337
330
}
338
331
339
- if (!$ isTagInt ) {
340
- // convert string tags into their int forms
341
- foreach ($ changes as &$ blocks ) {
342
- foreach ($ blocks as &$ change ) {
343
- $ change ['tag ' ] = SequenceMatcher::opStrToInt ($ change ['tag ' ]);
344
- }
332
+ foreach ($ changes as &$ hunks ) {
333
+ foreach ($ hunks as &$ block ) {
334
+ $ block ['tag ' ] = SequenceMatcher::opStrToInt ($ block ['tag ' ]);
345
335
}
346
-
347
- unset($ blocks , $ change );
348
336
}
349
-
350
- return $ changes ;
351
337
}
352
338
}
0 commit comments