Skip to content

Commit

Permalink
Optimize Sequence renderer
Browse files Browse the repository at this point in the history
* Reduction of cyclomatic complexity.
  • Loading branch information
DigiLive authored and DigiLive committed Dec 10, 2020
1 parent 7d973d3 commit bb0eed4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/jblond/Diff/Renderer/MainRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,23 @@ protected function renderSequences(): array
$oldBlock = $this->formatLines(array_slice($oldText, $startOld, $blockSizeOld));
$newBlock = $this->formatLines(array_slice($newText, $startNew, $blockSizeNew));

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

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

if ($tag == 'replace' || $tag == 'insert') {
// Inline differences or the new block doesn't exist in the old text.
$blocks[$lastBlock]['changed']['lines'] += $newBlock;
}
// Block of version2 doesn't exist in version1.
$blocks[$lastBlock]['changed']['lines'] += $newBlock;
}

$changes[] = $blocks;
}

Expand Down

0 comments on commit bb0eed4

Please sign in to comment.