Skip to content

Commit

Permalink
fix: Differ::getStatistics() not working when no difference
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Mar 7, 2024
1 parent 26f93d7 commit e6d485d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/Differ.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ final class Differ
* The constructor.
*
* @param string[] $old array containing the lines of the old string to compare
* @param string[] $new array containing the lines for the new string to compare
* @param string[] $new array containing the lines of the new string to compare
* @param array $options the options
*/
public function __construct(array $old, array $new, array $options = [])
Expand Down Expand Up @@ -290,6 +290,8 @@ public function getStatistics(): array
}
}

var_dump($this->oldSrcLength);

$ret['unmodified'] = $this->oldSrcLength - $ret['deleted'];
$ret['changedRatio'] = 1 - ($ret['unmodified'] / $this->oldSrcLength);

Expand All @@ -315,21 +317,21 @@ public function getGroupedOpcodes(): array
$old = $this->old;
$new = $this->new;

$this->getGroupedOpcodesPre($old, $new);

if ($this->oldNewComparison === 0 && $this->options['fullContextIfIdentical']) {
return [
$opcodes = [
[
[SequenceMatcher::OP_EQ, 0, \count($old), 0, \count($new)],
],
];
} else {
$opcodes = $this->sequenceMatcher
->setSequences($old, $new)
->getGroupedOpcodes($this->options['context'])
;
}

$this->getGroupedOpcodesPre($old, $new);

$opcodes = $this->sequenceMatcher
->setSequences($old, $new)
->getGroupedOpcodes($this->options['context'])
;

$this->getGroupedOpcodesPost($opcodes);

return $this->groupedOpcodes = $opcodes;
Expand All @@ -351,21 +353,21 @@ public function getGroupedOpcodesGnu(): array
$old = $this->old;
$new = $this->new;

$this->getGroupedOpcodesGnuPre($old, $new);

if ($this->oldNewComparison === 0 && $this->options['fullContextIfIdentical']) {
return [
$opcodes = [
[
[SequenceMatcher::OP_EQ, 0, \count($old), 0, \count($new)],
],
];
} else {
$opcodes = $this->sequenceMatcher
->setSequences($old, $new)
->getGroupedOpcodes($this->options['context'])
;
}

$this->getGroupedOpcodesGnuPre($old, $new);

$opcodes = $this->sequenceMatcher
->setSequences($old, $new)
->getGroupedOpcodes($this->options['context'])
;

$this->getGroupedOpcodesGnuPost($opcodes);

return $this->groupedOpcodesGnu = $opcodes;
Expand Down

0 comments on commit e6d485d

Please sign in to comment.