NonSymbolMatcher   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tokenizeDate() 0 14 4
A __construct() 0 3 1
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