Skip to content

Commit 23c59f8

Browse files
committed
Update jfcherng/php-sequence-matcher ^3.0
Signed-off-by: Jack Cherng <[email protected]>
1 parent 1eb6bbb commit 23c59f8

File tree

4 files changed

+16
-38
lines changed

4 files changed

+16
-38
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"require": {
2727
"php": "^7.1.3",
2828
"jfcherng/php-mb-string": "^1.3",
29-
"jfcherng/php-sequence-matcher": "^2.0",
29+
"jfcherng/php-sequence-matcher": "^3.0",
3030
"squizlabs/php_codesniffer": "^3.4"
3131
},
3232
"require-dev": {

composer.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Renderer/Html/AbstractHtml.php

+7-23
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getChanges(): array
5656

5757
foreach ($this->diff->getGroupedOpcodes() as $opcodes) {
5858
$blocks = [];
59-
$lastTag = null;
59+
$lastTag = 0;
6060
$lastBlock = 0;
6161

6262
foreach ($opcodes as [$tag, $i1, $i2, $j1, $j2]) {
@@ -88,20 +88,7 @@ public function getChanges(): array
8888
continue;
8989
}
9090

91-
/**
92-
* @todo By setting option "useIntOpcodes" for the sequence matcher,
93-
* this "if" could be further optimized by using bit operations.
94-
*
95-
* Like this: "if ($tag & (OP_INT_REP | OP_INT_DEL))"
96-
*
97-
* But int tag would be less readable while debugging.
98-
* Also, this would be a BC break for the output of the JSON renderer.
99-
* Is it worth doing?
100-
*/
101-
if (
102-
$tag === SequenceMatcher::OP_REP ||
103-
$tag === SequenceMatcher::OP_DEL
104-
) {
91+
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_DEL)) {
10592
$lines = \array_slice($old, $i1, $i2 - $i1);
10693
$lines = $this->formatLines($lines);
10794
$lines = \str_replace(
@@ -113,10 +100,7 @@ public function getChanges(): array
113100
$blocks[$lastBlock]['old']['lines'] += $lines;
114101
}
115102

116-
if (
117-
$tag === SequenceMatcher::OP_REP ||
118-
$tag === SequenceMatcher::OP_INS
119-
) {
103+
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_INS)) {
120104
$lines = \array_slice($new, $j1, $j2 - $j1);
121105
$lines = $this->formatLines($lines);
122106
$lines = \str_replace(
@@ -167,13 +151,13 @@ protected function renderChangedExtent(AbstractLineRenderer $lineRenderer, strin
167151
/**
168152
* Get the default block.
169153
*
170-
* @param string $tag the operation tag
171-
* @param int $i1 begin index of the diff of the old array
172-
* @param int $j1 begin index of the diff of the new array
154+
* @param int $tag the operation tag
155+
* @param int $i1 begin index of the diff of the old array
156+
* @param int $j1 begin index of the diff of the new array
173157
*
174158
* @return array the default block
175159
*/
176-
protected function getDefaultBlock(string $tag, int $i1, int $j1): array
160+
protected function getDefaultBlock(int $tag, int $i1, int $j1): array
177161
{
178162
return [
179163
'tag' => $tag,

src/Renderer/Text/Unified.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,11 @@ public function render(): string
4848
continue;
4949
}
5050

51-
if (
52-
$tag === SequenceMatcher::OP_REP ||
53-
$tag === SequenceMatcher::OP_DEL
54-
) {
51+
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_DEL)) {
5552
$ret .= $this->renderContext('-', $this->diff->getOld($i1, $i2));
5653
}
5754

58-
if (
59-
$tag === SequenceMatcher::OP_REP ||
60-
$tag === SequenceMatcher::OP_INS
61-
) {
55+
if ($tag & (SequenceMatcher::OP_REP | SequenceMatcher::OP_INS)) {
6256
$ret .= $this->renderContext('+', $this->diff->getNew($j1, $j2));
6357
}
6458
}

0 commit comments

Comments
 (0)