SqlParser\Utils\Formatter::getGroupLength PHP Метод

getGroupLength() публичный статический Метод

A group is delimited by a pair of brackets.
public static getGroupLength ( TokensList $list ) : integer
$list SqlParser\TokensList The list of tokens.
Результат integer
    public static function getGroupLength($list)
    {
        /**
         * The number of opening brackets found.
         * This counter starts at one because by the time this function called,
         * the list already advanced one position and the opening bracket was
         * already parsed.
         *
         * @var int $count
         */
        $count = 1;
        /**
         * The length of this group.
         *
         * @var int $length
         */
        $length = 0;
        for ($idx = $list->idx; $idx < $list->count; ++$idx) {
            // Counting the brackets.
            if ($list->tokens[$idx]->type === Token::TYPE_OPERATOR) {
                if ($list->tokens[$idx]->value === '(') {
                    ++$count;
                } elseif ($list->tokens[$idx]->value === ')') {
                    --$count;
                    if ($count == 0) {
                        break;
                    }
                }
            }
            // Keeping track of this group's length.
            $length += mb_strlen($list->tokens[$idx]->value, 'UTF-8');
        }
        return $length;
    }