SubLexerChain::getTokenAt()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 2
crap 3
1
<?php
2
namespace Xiag\Rql\Parser;
3
4
class SubLexerChain implements SubLexerInterface
5
{
6
    /**
7
     * @var SubLexerInterface[]
8
     */
9
    protected $subLexers = [];
10
11
    /**
12
     * @param SubLexerInterface $subLexer
13
     * @return $this
14
     */
15 85
    public function addSubLexer(SubLexerInterface $subLexer)
16
    {
17 85
        $this->subLexers[] = $subLexer;
18 85
        return $this;
19
    }
20
21
    /**
22
     * @inheritdoc
23
     */
24 85
    public function getTokenAt($code, $cursor)
25
    {
26 85
        foreach ($this->subLexers as $subLexer) {
27 85
            $token = $subLexer->getTokenAt($code, $cursor);
28 85
            if ($token !== null) {
29 85
                return $token;
30
            }
31 85
        }
32
33 2
        return null;
34
    }
35
}
36