NonSymbolMatcher::tokenizeDate()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 2
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Popy\Calendar\Parser\DateLexer;
4
5
use Popy\Calendar\Parser\FormatToken;
6
use Popy\Calendar\Parser\DateLexerResult;
7
use Popy\Calendar\Parser\DateLexerInterface;
8
9
/**
10
 * Very basic lexer, matching a single token as a litteral one.
11
 */
12
class NonSymbolMatcher implements DateLexerInterface
13
{
14
    /**
15
     * Token.
16
     *
17
     * @var FormatToken
18
     */
19
    protected $token;
20
21
    /**
22
     * Class constructor.
23
     *
24
     * @param FormatToken $token
25
     */
26
    public function __construct(FormatToken $token)
27
    {
28
        $this->token = $token;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function tokenizeDate($string, $offset = 0)
35
    {
36
        if ($this->token->isType(FormatToken::TYPE_EOF)) {
37
            if (strlen($string) <= $offset) {
38
                return new DateLexerResult($offset);
39
            }
40
41
            return;
42
        }
43
44
        $len = strlen($this->token->getValue());
45
46
        if (substr($string, $offset, $len) === $this->token->getValue()) {
47
            return new DateLexerResult($offset + $len);
48
        }
49
    }
50
}
51