private function precalculate() { $an = Normalizer::fromString($this->a); $bn = Normalizer::fromString($this->b); $al = $an->getLines(true); $bl = $bn->getLines(true); $slm = new SequenceMatcher($al, $bl, 0.7); $lops = $slm->getOpCodes(true); $ops = []; foreach ($lops as $lop) { $atn = Normalizer::fromArray($lop[5]); $btn = Normalizer::fromArray($lop[6]); $at = $atn->getTokens(); $bt = $btn->getTokens(); $swm = new SequenceMatcher($at, $bt, 0.9); $wops = $swm->getOpCodes(true); $op = $lop; $op['wops'] = $wops; $ops[] = $op; } $this->ops = $ops; foreach ($this->ops as $o => $lop) { foreach ($lop['wops'] as $wop) { list($wtag, $as, $al, $bs, $bl, $at, $bt) = $wop; switch ($wop[0]) { case 'delete': $this->removals += count($at); break; case 'insert': $this->additions += count($bt); break; case 'replace': $this->removals += count($at); $this->additions += count($bt); break; } } } }