Passed
Push — develop ( cb60d7...ef7d65 )
by Maarten de
07:14
created

Stream::hasNext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cloudstek\SCIM\FilterParser\Tokenizer;
6
7
use Nette\Tokenizer\Exception as TokenizerException;
8
use Nette\Tokenizer\Token;
9
10
/**
11
 * Stream class.
12
 */
13
class Stream extends \Nette\Tokenizer\Stream
14
{
15
    /**
16
     * Match next token.
17
     *
18
     * Make sure the next token matches a certain type or value and return it.
19
     *
20
     * @param int|string ...$args
21
     *
22
     * @throws TokenizerException When next token does not match the given type(s) or value(s).
23
     *
24
     * @return Token
25
     */
26
    public function matchNext(...$args): Token
27
    {
28
        $token = $this->nextToken();
29
30
        if ($token === null) {
31
            throw new TokenizerException('Unexpected end of string.');
32
        } elseif ($this->isCurrent(...$args) === false) {
33
            [$line, $col] = Tokenizer::getCoordinates($token->value, $token->offset);
34
35
            throw new TokenizerException(
36
                sprintf(
37
                    'Unexpected "%s" on line %d, column %d.',
38
                    trim($token->value),
39
                    $line,
40
                    $col
41
                )
42
            );
43
        }
44
45
        return $token;
46
    }
47
48
    /**
49
     * Whether we have more tokens in the stream.
50
     *
51
     * @return bool
52
     */
53
    public function hasNext(): bool
54
    {
55
        return $this->position < (count($this->tokens) - 1);
56
    }
57
}
58