PhpCsFixer\Fixer\Alias\EregToPregFixer::getBestDelimiter PHP Method

getBestDelimiter() private method

Get the delimiter that would require the least escaping in a regular expression.
private getBestDelimiter ( string $pattern ) : string
$pattern string the regular expression
return string the preg delimiter
    private function getBestDelimiter($pattern)
    {
        // try do find something that's not used
        $delimiters = array();
        foreach (self::$delimiters as $k => $d) {
            if (false === strpos($pattern, $d)) {
                return $d;
            }
            $delimiters[$d] = array(substr_count($pattern, $d), $k);
        }
        // return the least used delimiter, using the position in the list as a tie breaker
        uasort($delimiters, function ($a, $b) {
            if ($a[0] === $b[0]) {
                return Utils::cmpInt($a, $b);
            }
            return $a[0] < $b[0] ? -1 : 1;
        });
        return key($delimiters);
    }