diff --git a/README.md b/README.md index 581f8ed4..bfeff7d6 100644 --- a/README.md +++ b/README.md @@ -181,13 +181,13 @@ $result = $diff->render($renderer); [ { "tag": "rep", - "base": { + "old": { "offset": 0, "lines": [ "<p>Hello World!</p>" ] }, - "changed": { + "new": { "offset": 0, "lines": [ "<div>Hello World!</div>" @@ -196,13 +196,13 @@ $result = $diff->render($renderer); }, { "tag": "eq", - "base": { + "old": { "offset": 1, "lines": [ "~~~~~~~~~~~~~~~~~~~" ] }, - "changed": { + "new": { "offset": 1, "lines": [ "~~~~~~~~~~~~~~~~~~~" @@ -211,11 +211,11 @@ $result = $diff->render($renderer); }, { "tag": "ins", - "base": { + "old": { "offset": 2, "lines": [] }, - "changed": { + "new": { "offset": 2, "lines": [ "Let's add a new line here." @@ -224,13 +224,13 @@ $result = $diff->render($renderer); }, { "tag": "eq", - "base": { + "old": { "offset": 2, "lines": [ "X" ] }, - "changed": { + "new": { "offset": 3, "lines": [ "X" @@ -241,13 +241,13 @@ $result = $diff->render($renderer); [ { "tag": "eq", - "base": { + "old": { "offset": 6, "lines": [ "N" ] }, - "changed": { + "new": { "offset": 7, "lines": [ "N" @@ -256,13 +256,13 @@ $result = $diff->render($renderer); }, { "tag": "rep", - "base": { + "old": { "offset": 7, "lines": [ "Do you know in Chinese, \"金槍魚罐頭\" means tuna can." ] }, - "changed": { + "new": { "offset": 8, "lines": [ "Do you know in Japanese, \"魚の缶詰\" means fish can." @@ -271,14 +271,14 @@ $result = $diff->render($renderer); }, { "tag": "eq", - "base": { + "old": { "offset": 8, "lines": [ "This is just a useless line.", "G" ] }, - "changed": { + "new": { "offset": 9, "lines": [ "This is just a useless line.", @@ -288,26 +288,26 @@ $result = $diff->render($renderer); }, { "tag": "del", - "base": { + "old": { "offset": 10, "lines": [ "// @todo Remember to delete this line" ] }, - "changed": { + "new": { "offset": 11, "lines": [] } }, { "tag": "eq", - "base": { + "old": { "offset": 11, "lines": [ "Say hello to my neighbors." ] }, - "changed": { + "new": { "offset": 11, "lines": [ "Say hello to my neighbors." diff --git a/src/Renderer/Html/AbstractHtml.php b/src/Renderer/Html/AbstractHtml.php index 78137c72..a71c6e9c 100644 --- a/src/Renderer/Html/AbstractHtml.php +++ b/src/Renderer/Html/AbstractHtml.php @@ -80,8 +80,8 @@ public function getChanges(): array if (!empty($lines = \array_slice($old, $i1, ($i2 - $i1)))) { $formattedLines = $this->formatLines($lines); - $blocks[$lastBlock]['base']['lines'] += $formattedLines; - $blocks[$lastBlock]['changed']['lines'] += $formattedLines; + $blocks[$lastBlock]['old']['lines'] += $formattedLines; + $blocks[$lastBlock]['new']['lines'] += $formattedLines; } continue; @@ -109,7 +109,7 @@ public function getChanges(): array $lines ); - $blocks[$lastBlock]['base']['lines'] += $lines; + $blocks[$lastBlock]['old']['lines'] += $lines; } if ( @@ -124,7 +124,7 @@ public function getChanges(): array $lines ); - $blocks[$lastBlock]['changed']['lines'] += $lines; + $blocks[$lastBlock]['new']['lines'] += $lines; } } @@ -167,8 +167,8 @@ protected function renderChangedExtent(AbstractLineRenderer $lineRenderer, strin * Get the default block. * * @param string $tag the operation tag - * @param int $i1 begin index of the diff of the source - * @param int $j1 begin index of the diff of the destination + * @param int $i1 begin index of the diff of the old array + * @param int $j1 begin index of the diff of the new array * * @return array the default block */ @@ -176,11 +176,11 @@ protected function getDefaultBlock(string $tag, int $i1, int $j1): array { return [ 'tag' => $tag, - 'base' => [ + 'old' => [ 'offset' => $i1, 'lines' => [], ], - 'changed' => [ + 'new' => [ 'offset' => $j1, 'lines' => [], ], diff --git a/src/Renderer/Html/Inline.php b/src/Renderer/Html/Inline.php index 83f5f4c0..4483cf54 100644 --- a/src/Renderer/Html/Inline.php +++ b/src/Renderer/Html/Inline.php @@ -124,14 +124,14 @@ protected function renderTableEqual(array $change): string { $html = ''; - foreach ($change['base']['lines'] as $no => $line) { - $oldLineNum = $change['base']['offset'] + $no + 1; - $newLineNum = $change['changed']['offset'] + $no + 1; + foreach ($change['old']['lines'] as $no => $line) { + $oldLineNum = $change['old']['offset'] + $no + 1; + $newLineNum = $change['new']['offset'] + $no + 1; $html .= '' . - '' . $oldLineNum . '' . - '' . $newLineNum . '' . + '' . $oldLineNum . '' . + '' . $newLineNum . '' . '' . '' . $line . '' . ''; @@ -151,13 +151,13 @@ protected function renderTableInsert(array $change): string { $html = ''; - foreach ($change['changed']['lines'] as $no => $newLine) { - $newLineNum = $change['changed']['offset'] + $no + 1; + foreach ($change['new']['lines'] as $no => $newLine) { + $newLineNum = $change['new']['offset'] + $no + 1; $html .= '' . '' . - '' . $newLineNum . '' . + '' . $newLineNum . '' . '+' . '' . $newLine . '' . ''; @@ -177,12 +177,12 @@ protected function renderTableDelete(array $change): string { $html = ''; - foreach ($change['base']['lines'] as $no => $oldLine) { - $oldLineNum = $change['base']['offset'] + $no + 1; + foreach ($change['old']['lines'] as $no => $oldLine) { + $oldLineNum = $change['old']['offset'] + $no + 1; $html .= '' . - '' . $oldLineNum . '' . + '' . $oldLineNum . '' . '' . '-' . '' . $oldLine . '' . @@ -203,25 +203,25 @@ protected function renderTableReplace(array $change): string { $html = ''; - foreach ($change['base']['lines'] as $no => $oldLine) { - $oldLineNum = $change['base']['offset'] + $no + 1; + foreach ($change['old']['lines'] as $no => $oldLine) { + $oldLineNum = $change['old']['offset'] + $no + 1; $html .= '' . - '' . $oldLineNum . '' . + '' . $oldLineNum . '' . '' . '-' . '' . $oldLine . '' . ''; } - foreach ($change['changed']['lines'] as $no => $newLine) { - $newLineNum = $change['changed']['offset'] + $no + 1; + foreach ($change['new']['lines'] as $no => $newLine) { + $newLineNum = $change['new']['offset'] + $no + 1; $html .= '' . '' . - '' . $newLineNum . '' . + '' . $newLineNum . '' . '+' . '' . $newLine . '' . ''; diff --git a/src/Renderer/Html/SideBySide.php b/src/Renderer/Html/SideBySide.php index c32b8405..61ea570c 100644 --- a/src/Renderer/Html/SideBySide.php +++ b/src/Renderer/Html/SideBySide.php @@ -122,15 +122,15 @@ protected function renderTableEqual(array $change): string { $html = ''; - foreach ($change['base']['lines'] as $no => $line) { - $oldLineNum = $change['base']['offset'] + $no + 1; - $newLine = $change['changed']['offset'] + $no + 1; + foreach ($change['old']['lines'] as $no => $line) { + $oldLineNum = $change['old']['offset'] + $no + 1; + $newLine = $change['new']['offset'] + $no + 1; $html .= '' . - '' . $oldLineNum . '' . + '' . $oldLineNum . '' . '' . $line . '' . - '' . $newLine . '' . + '' . $newLine . '' . '' . $line . '' . ''; } @@ -149,14 +149,14 @@ protected function renderTableInsert(array $change): string { $html = ''; - foreach ($change['changed']['lines'] as $no => $newLine) { - $newLineNum = $change['changed']['offset'] + $no + 1; + foreach ($change['new']['lines'] as $no => $newLine) { + $newLineNum = $change['new']['offset'] + $no + 1; $html .= '' . '' . '' . - '' . $newLineNum . '' . + '' . $newLineNum . '' . '' . $newLine . '' . ''; } @@ -175,12 +175,12 @@ protected function renderTableDelete(array $change): string { $html = ''; - foreach ($change['base']['lines'] as $no => $oldLine) { - $oldLineNum = $change['base']['offset'] + $no + 1; + foreach ($change['old']['lines'] as $no => $oldLine) { + $oldLineNum = $change['old']['offset'] + $no + 1; $html .= '' . - '' . $oldLineNum . '' . + '' . $oldLineNum . '' . '' . $oldLine . '' . '' . '' . @@ -201,13 +201,13 @@ protected function renderTableReplace(array $change): string { $html = ''; - if (\count($change['base']['lines']) >= \count($change['changed']['lines'])) { - foreach ($change['base']['lines'] as $no => $oldLine) { - $oldLineNum = $change['base']['offset'] + $no + 1; + if (\count($change['old']['lines']) >= \count($change['new']['lines'])) { + foreach ($change['old']['lines'] as $no => $oldLine) { + $oldLineNum = $change['old']['offset'] + $no + 1; - if (isset($change['changed']['lines'][$no])) { - $newLineNum = $change['base']['offset'] + $no + 1; - $newLine = '' . $change['changed']['lines'][$no] . ''; + if (isset($change['new']['lines'][$no])) { + $newLineNum = $change['old']['offset'] + $no + 1; + $newLine = '' . $change['new']['lines'][$no] . ''; } else { $newLineNum = ''; $newLine = ''; @@ -215,19 +215,19 @@ protected function renderTableReplace(array $change): string $html .= '' . - '' . $oldLineNum . '' . + '' . $oldLineNum . '' . '' . $oldLine . '' . - '' . $newLineNum . '' . + '' . $newLineNum . '' . '' . $newLine . '' . ''; } } else { - foreach ($change['changed']['lines'] as $no => $newLine) { - $newLineNum = $change['changed']['offset'] + $no + 1; + foreach ($change['new']['lines'] as $no => $newLine) { + $newLineNum = $change['new']['offset'] + $no + 1; - if (isset($change['base']['lines'][$no])) { - $oldLineNum = $change['base']['offset'] + $no + 1; - $oldLine = '' . $change['base']['lines'][$no] . ''; + if (isset($change['old']['lines'][$no])) { + $oldLineNum = $change['old']['offset'] + $no + 1; + $oldLine = '' . $change['old']['lines'][$no] . ''; } else { $oldLineNum = ''; $oldLine = ''; @@ -235,9 +235,9 @@ protected function renderTableReplace(array $change): string $html .= '' . - '' . $oldLineNum . '' . + '' . $oldLineNum . '' . '' . $oldLine . '' . - '' . $newLineNum . '' . + '' . $newLineNum . '' . '' . $newLine . '' . ''; }