Skip to content

Commit 297d6a9

Browse files
committed
fix: Differ::getStatistics() not working when no difference
Signed-off-by: Jack Cherng <[email protected]>
1 parent 29535c4 commit 297d6a9

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/Differ.php

+17-15
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ final class Differ
127127
* The constructor.
128128
*
129129
* @param string[] $old array containing the lines of the old string to compare
130-
* @param string[] $new array containing the lines for the new string to compare
130+
* @param string[] $new array containing the lines of the new string to compare
131131
* @param array $options the options
132132
*/
133133
public function __construct(array $old, array $new, array $options = [])
@@ -296,6 +296,8 @@ public function getStatistics(): array
296296
}
297297
}
298298

299+
var_dump($this->oldSrcLength);
300+
299301
$ret['unmodified'] = $this->oldSrcLength - $ret['deleted'];
300302
$ret['changedRatio'] = 1 - ($ret['unmodified'] / $this->oldSrcLength);
301303

@@ -321,20 +323,20 @@ public function getGroupedOpcodes(): array
321323
$old = $this->old;
322324
$new = $this->new;
323325

326+
$this->getGroupedOpcodesPre($old, $new);
327+
324328
if ($this->oldNewComparison === 0 && $this->options['fullContextIfIdentical']) {
325-
return [
329+
$opcodes = [
326330
[
327331
[SequenceMatcher::OP_EQ, 0, \count($old), 0, \count($new)],
328332
],
329333
];
334+
} else {
335+
$opcodes = $this->sequenceMatcher
336+
->setSequences($old, $new)
337+
->getGroupedOpcodes($this->options['context']);
330338
}
331339

332-
$this->getGroupedOpcodesPre($old, $new);
333-
334-
$opcodes = $this->sequenceMatcher
335-
->setSequences($old, $new)
336-
->getGroupedOpcodes($this->options['context']);
337-
338340
$this->getGroupedOpcodesPost($opcodes);
339341

340342
return $this->groupedOpcodes = $opcodes;
@@ -356,20 +358,20 @@ public function getGroupedOpcodesGnu(): array
356358
$old = $this->old;
357359
$new = $this->new;
358360

361+
$this->getGroupedOpcodesGnuPre($old, $new);
362+
359363
if ($this->oldNewComparison === 0 && $this->options['fullContextIfIdentical']) {
360-
return [
364+
$opcodes = [
361365
[
362366
[SequenceMatcher::OP_EQ, 0, \count($old), 0, \count($new)],
363367
],
364368
];
369+
} else {
370+
$opcodes = $this->sequenceMatcher
371+
->setSequences($old, $new)
372+
->getGroupedOpcodes($this->options['context']);
365373
}
366374

367-
$this->getGroupedOpcodesGnuPre($old, $new);
368-
369-
$opcodes = $this->sequenceMatcher
370-
->setSequences($old, $new)
371-
->getGroupedOpcodes($this->options['context']);
372-
373375
$this->getGroupedOpcodesGnuPost($opcodes);
374376

375377
return $this->groupedOpcodesGnu = $opcodes;

0 commit comments

Comments
 (0)