Skip to content

Commit 576830c

Browse files
DigiLiveJBlond
authored andcommitted
Optimize Sequence renderer
* Reduction of cyclomatic complexity.
1 parent 9699b5b commit 576830c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/jblond/Diff/Renderer/MainRenderer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,23 @@ protected function renderSequences(): array
146146
$oldBlock = $this->formatLines(array_slice($oldText, $startOld, $blockSizeOld));
147147
$newBlock = $this->formatLines(array_slice($newText, $startNew, $blockSizeNew));
148148

149-
if ($tag == 'equal') {
150-
// Old block equals New block
149+
if ($tag != 'delete' && $tag != 'insert') {
150+
// Old block "equals" New block or is replaced.
151151
$blocks[$lastBlock]['base']['lines'] += $oldBlock;
152152
$blocks[$lastBlock]['changed']['lines'] += $newBlock;
153153
continue;
154154
}
155155

156-
if ($tag == 'replace' || $tag == 'delete') {
157-
// Inline differences or old block doesn't exist in the new text.
156+
if ($tag == 'delete') {
157+
// Block of version1 doesn't exist in version2.
158158
$blocks[$lastBlock]['base']['lines'] += $oldBlock;
159+
continue;
159160
}
160161

161-
if ($tag == 'replace' || $tag == 'insert') {
162-
// Inline differences or the new block doesn't exist in the old text.
163-
$blocks[$lastBlock]['changed']['lines'] += $newBlock;
164-
}
162+
// Block of version2 doesn't exist in version1.
163+
$blocks[$lastBlock]['changed']['lines'] += $newBlock;
165164
}
165+
166166
$changes[] = $blocks;
167167
}
168168

0 commit comments

Comments
 (0)