diff --git a/src/Differ.php b/src/Differ.php index 61b79ec..429732f 100644 --- a/src/Differ.php +++ b/src/Differ.php @@ -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 = []) @@ -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); @@ -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; @@ -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;