Patchwork\CodeManipulation\Source::next PHP Method

next() public method

public next ( $types, $offset )
    function next($types, $offset)
    {
        if (!is_array($types)) {
            $candidates = Utils\access($this->tokensByType, $types, []);
            return Utils\firstGreaterThan($candidates, $offset);
        }
        $result = INF;
        foreach ($types as $type) {
            $result = min($this->next($type, $offset), $result);
        }
        return $result;
    }

Usage Example

Example #1
0
function collectNamespaceBoundaries(Source $s)
{
    if (!$s->has(T_NAMESPACE)) {
        return ['' => [[0, INF]]];
    }
    $result = [];
    foreach ($s->all(T_NAMESPACE) as $keyword) {
        if ($s->next(';', $keyword) < $s->next(Generic\LEFT_CURLY, $keyword)) {
            return [scanQualifiedName($s, $keyword + 1) => [[0, INF]]];
        }
        $begin = $s->next(Generic\LEFT_CURLY, $keyword) + 1;
        $end = $s->match($begin) - 1;
        $name = scanQualifiedName($s, $keyword + 1);
        if (!isset($result[$name])) {
            $result[$name] = [];
        }
        $result[$name][] = [$begin, $end];
    }
    return $result;
}