public function levenshtein()
    {
        $diffs = $this->getChanges();

        $levenshtein = 0;
        $insertions = 0;
        $deletions = 0;

        foreach ($diffs as $change) {
            $op = $change[0];
            $text = $change[1];

            switch ($op) {
                case self::INSERT:
                    $insertions += mb_strlen($text);
                    break;
                case self::DELETE:
                    $deletions += mb_strlen($text);
                    break;
                case self::EQUAL:
                    // A deletion and an insertion is one substitution.
                    $levenshtein += max($insertions, $deletions);
                    $insertions = 0;
                    $deletions = 0;
                    break;
            }
        }
        $levenshtein += max($insertions, $deletions);

        return $levenshtein;
    }