Skip to content

Commit bd00670

Browse files
committed
Code tidy
Signed-off-by: Jack Cherng <[email protected]>
1 parent 2031306 commit bd00670

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/Diff.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ public function setOldNew(array $old, array $new): self
9292
*/
9393
public function setOld(array $old): self
9494
{
95-
if ($this->old !== $old) {
96-
$this->old = $old;
97-
$this->groupedCodes = null;
98-
$this->sequenceMatcher->setSeq1($old);
99-
}
95+
$this->old = $old;
96+
$this->sequenceMatcher->setSeq1($old);
97+
$this->resetCachedResults();
10098

10199
return $this;
102100
}
@@ -110,11 +108,9 @@ public function setOld(array $old): self
110108
*/
111109
public function setNew(array $new): self
112110
{
113-
if ($this->new !== $new) {
114-
$this->new = $new;
115-
$this->groupedCodes = null;
116-
$this->sequenceMatcher->setSeq2($new);
117-
}
111+
$this->new = $new;
112+
$this->sequenceMatcher->setSeq2($new);
113+
$this->resetCachedResults();
118114

119115
return $this;
120116
}
@@ -131,6 +127,7 @@ public function setOptions(array $options): self
131127
$this->options = $options + static::$defaultOptions;
132128

133129
$this->sequenceMatcher->setOptions($this->options);
130+
$this->resetCachedResults();
134131

135132
return $this;
136133
}
@@ -201,6 +198,18 @@ public function getGroupedOpcodes(): array
201198
$this->sequenceMatcher->getGroupedOpcodes($this->options['context']);
202199
}
203200

201+
/**
202+
* Reset cached results.
203+
*
204+
* @return self
205+
*/
206+
public function resetCachedResults(): self
207+
{
208+
$this->groupedCodes = null;
209+
210+
return $this;
211+
}
212+
204213
/**
205214
* Render a diff using the supplied rendering class and return it.
206215
*

src/Renderer/Html/AbstractHtml.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ public function getChanges(): array
7777
$lastTag = $tag;
7878

7979
if ($tag === SequenceMatcher::OP_EQ) {
80-
if (!empty($lines = \array_slice($old, $i1, ($i2 - $i1)))) {
80+
/**
81+
* @todo Technically this is wrong.
82+
* The old and the new may not be exactly the same
83+
* because of ignoreCase and ignoreWhitespace.
84+
*/
85+
if (!empty($lines = \array_slice($old, $i1, $i2 - $i1))) {
8186
$formattedLines = $this->formatLines($lines);
8287

8388
$blocks[$lastBlock]['base']['lines'] += $formattedLines;
@@ -101,7 +106,7 @@ public function getChanges(): array
101106
$tag === SequenceMatcher::OP_REP ||
102107
$tag === SequenceMatcher::OP_DEL
103108
) {
104-
$lines = \array_slice($old, $i1, ($i2 - $i1));
109+
$lines = \array_slice($old, $i1, $i2 - $i1);
105110
$lines = $this->formatLines($lines);
106111
$lines = \str_replace(
107112
RendererConstant::HTML_CLOSURES,
@@ -116,7 +121,7 @@ public function getChanges(): array
116121
$tag === SequenceMatcher::OP_REP ||
117122
$tag === SequenceMatcher::OP_INS
118123
) {
119-
$lines = \array_slice($new, $j1, ($j2 - $j1));
124+
$lines = \array_slice($new, $j1, $j2 - $j1);
120125
$lines = $this->formatLines($lines);
121126
$lines = \str_replace(
122127
RendererConstant::HTML_CLOSURES,

src/Renderer/Html/LineRenderer/AbstractLineRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class AbstractLineRenderer implements LineRendererInterface
2929
/**
3030
* The constructor.
3131
*
32-
* @param array $diffOptions the difference options
32+
* @param array $diffOptions the diff options
3333
* @param array $templateOptions the template options
3434
*/
3535
public function __construct(array $diffOptions, array $templateOptions)
@@ -44,7 +44,7 @@ public function __construct(array $diffOptions, array $templateOptions)
4444
/**
4545
* Set the diff options.
4646
*
47-
* @param array $diffOptions the options
47+
* @param array $diffOptions the diff options
4848
*
4949
* @return self
5050
*/

0 commit comments

Comments
 (0)