Skip to content

Commit e96e971

Browse files
committed
Rename some "tag" to "op"
Signed-off-by: Jack Cherng <[email protected]>
1 parent 2dd547c commit e96e971

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

src/Renderer/Html/AbstractHtml.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ abstract class AbstractHtml extends AbstractRenderer
2323
const IS_TEXT_RENDERER = false;
2424

2525
/**
26-
* @var array array of the different opcode tags and how they map to the HTML class
26+
* @var array array of the different opcodes and how they are mapped to HTML classes
27+
*
28+
* @todo rename to OP_CLASS_MAP in v7
2729
*/
2830
const TAG_CLASS_MAP = [
2931
SequenceMatcher::OP_DEL => 'del',
@@ -64,27 +66,27 @@ public function getChanges(Differ $differ): array
6466

6567
foreach ($differ->getGroupedOpcodes() as $opcodes) {
6668
$hunk = [];
67-
$lastTag = SequenceMatcher::OP_NOP;
69+
$lastOp = SequenceMatcher::OP_NOP;
6870
$lastBlock = 0;
6971

70-
foreach ($opcodes as [$tag, $i1, $i2, $j1, $j2]) {
72+
foreach ($opcodes as [$op, $i1, $i2, $j1, $j2]) {
7173
if (
72-
$tag === SequenceMatcher::OP_REP &&
74+
$op === SequenceMatcher::OP_REP &&
7375
$i2 - $i1 === $j2 - $j1
7476
) {
7577
for ($i = 0; $i < $i2 - $i1; ++$i) {
7678
$this->renderChangedExtent($lineRenderer, $old[$i1 + $i], $new[$j1 + $i]);
7779
}
7880
}
7981

80-
if ($tag !== $lastTag) {
81-
$hunk[] = $this->getDefaultBlock($tag, $i1, $j1);
82+
if ($op !== $lastOp) {
83+
$hunk[] = $this->getDefaultBlock($op, $i1, $j1);
8284
$lastBlock = \count($hunk) - 1;
8385
}
8486

85-
$lastTag = $tag;
87+
$lastOp = $op;
8688

87-
if ($tag === SequenceMatcher::OP_EQ) {
89+
if ($op === SequenceMatcher::OP_EQ) {
8890
// note that although we are in a OP_EQ situation,
8991
// the old and the new may not be exactly the same
9092
// because of ignoreCase, ignoreWhitespace, etc
@@ -96,7 +98,7 @@ public function getChanges(Differ $differ): array
9698
continue;
9799
}
98100

99-
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_DEL)) {
101+
if ($op & (SequenceMatcher::OP_REP | SequenceMatcher::OP_DEL)) {
100102
$lines = \array_slice($old, $i1, $i2 - $i1);
101103
$lines = $this->formatLines($lines);
102104
$lines = \str_replace(
@@ -108,7 +110,7 @@ public function getChanges(Differ $differ): array
108110
$hunk[$lastBlock]['old']['lines'] = $lines;
109111
}
110112

111-
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_INS)) {
113+
if ($op & (SequenceMatcher::OP_REP | SequenceMatcher::OP_INS)) {
112114
$lines = \array_slice($new, $j1, $j2 - $j1);
113115
$lines = $this->formatLines($lines);
114116
$lines = \str_replace(
@@ -182,16 +184,18 @@ protected function renderChangedExtent(AbstractLineRenderer $lineRenderer, strin
182184
/**
183185
* Get the default block.
184186
*
185-
* @param int $tag the operation tag
186-
* @param int $i1 begin index of the diff of the old array
187-
* @param int $j1 begin index of the diff of the new array
187+
* @param int $op the operation
188+
* @param int $i1 begin index of the diff of the old array
189+
* @param int $j1 begin index of the diff of the new array
188190
*
189191
* @return array the default block
192+
*
193+
* @todo rename tag to op in v7
190194
*/
191-
protected function getDefaultBlock(int $tag, int $i1, int $j1): array
195+
protected function getDefaultBlock(int $op, int $i1, int $j1): array
192196
{
193197
return [
194-
'tag' => $tag,
198+
'tag' => $op,
195199
'old' => [
196200
'offset' => $i1,
197201
'lines' => [],

src/Renderer/Html/LineRenderer/Char.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface
2121
$opcodes = $this->getChangedExtentSegments($mbOld->toArray(), $mbNew->toArray());
2222

2323
// reversely iterate opcodes
24-
foreach (ReverseIterator::fromArray($opcodes) as [$tag, $i1, $i2, $j1, $j2]) {
25-
switch ($tag) {
24+
foreach (ReverseIterator::fromArray($opcodes) as [$op, $i1, $i2, $j1, $j2]) {
25+
switch ($op) {
2626
case SequenceMatcher::OP_DEL:
2727
$mbOld->str_enclose_i(RendererConstant::HTML_CLOSURES, $i1, $i2 - $i1);
2828

src/Renderer/Html/LineRenderer/Word.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function render(MbString $mbOld, MbString $mbNew): LineRendererInterface
2626
$opcodes = $this->getChangedExtentSegments($oldWords, $newWords);
2727

2828
// reversely iterate opcodes
29-
foreach (ReverseIterator::fromArray($opcodes) as [$tag, $i1, $i2, $j1, $j2]) {
30-
switch ($tag) {
29+
foreach (ReverseIterator::fromArray($opcodes) as [$op, $i1, $i2, $j1, $j2]) {
30+
switch ($op) {
3131
case SequenceMatcher::OP_DEL:
3232
$oldWords[$i1] = RendererConstant::HTML_CLOSURES[0] . $oldWords[$i1];
3333
$oldWords[$i2 - 1] .= RendererConstant::HTML_CLOSURES[1];

src/Renderer/Text/Context.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class Context extends AbstractText
2323
];
2424

2525
/**
26-
* @var array array of the different opcode tags and how they map to the context diff equivalent
26+
* @var array array of the different opcodes and their context diff equivalents
2727
*/
2828
const TAG_MAP = [
2929
SequenceMatcher::OP_DEL => '-',
@@ -83,13 +83,13 @@ protected function renderBlockOld(array $opcodes, Differ $differ): string
8383
{
8484
$ret = '';
8585

86-
foreach ($opcodes as [$tag, $i1, $i2, $j1, $j2]) {
87-
if ($tag === SequenceMatcher::OP_INS) {
86+
foreach ($opcodes as [$op, $i1, $i2, $j1, $j2]) {
87+
if ($op === SequenceMatcher::OP_INS) {
8888
continue;
8989
}
9090

9191
$ret .= $this->renderContext(
92-
self::TAG_MAP[$tag],
92+
self::TAG_MAP[$op],
9393
$differ->getOld($i1, $i2)
9494
);
9595
}
@@ -107,13 +107,13 @@ protected function renderBlockNew(array $opcodes, Differ $differ): string
107107
{
108108
$ret = '';
109109

110-
foreach ($opcodes as [$tag, $i1, $i2, $j1, $j2]) {
111-
if ($tag === SequenceMatcher::OP_DEL) {
110+
foreach ($opcodes as [$op, $i1, $i2, $j1, $j2]) {
111+
if ($op === SequenceMatcher::OP_DEL) {
112112
continue;
113113
}
114114

115115
$ret .= $this->renderContext(
116-
self::TAG_MAP[$tag],
116+
self::TAG_MAP[$op],
117117
$differ->getNew($j1, $j2)
118118
);
119119
}
@@ -124,7 +124,7 @@ protected function renderBlockNew(array $opcodes, Differ $differ): string
124124
/**
125125
* Render the context array with the symbol.
126126
*
127-
* @param string $symbol the symbol
127+
* @param string $symbol the leading symbol
128128
* @param array $context the context
129129
*/
130130
protected function renderContext(string $symbol, array $context): string

src/Renderer/Text/Unified.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ protected function renderWorker(Differ $differ): string
4343

4444
$ret .= $this->renderHunkHeader($i1 + 1, $i2 - $i1, $j1 + 1, $j2 - $j1);
4545

46-
foreach ($opcodes as [$tag, $i1, $i2, $j1, $j2]) {
47-
if ($tag === SequenceMatcher::OP_EQ) {
46+
foreach ($opcodes as [$op, $i1, $i2, $j1, $j2]) {
47+
if ($op === SequenceMatcher::OP_EQ) {
4848
$ret .= $this->renderContext(' ', $differ->getOld($i1, $i2));
4949

5050
continue;
5151
}
5252

53-
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_DEL)) {
53+
if ($op & (SequenceMatcher::OP_REP | SequenceMatcher::OP_DEL)) {
5454
$ret .= $this->renderContext('-', $differ->getOld($i1, $i2));
5555
}
5656

57-
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_INS)) {
57+
if ($op & (SequenceMatcher::OP_REP | SequenceMatcher::OP_INS)) {
5858
$ret .= $this->renderContext('+', $differ->getNew($j1, $j2));
5959
}
6060
}

0 commit comments

Comments
 (0)