Alternatives   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tokenizeDate() 0 6 3
A addLexer() 0 3 1
1
<?php
2
3
namespace Popy\Calendar\Parser\DateLexer;
4
5
use Popy\Calendar\Parser\DateLexerResult;
6
use Popy\Calendar\Parser\DateLexerInterface;
7
8
/**
9
 * Alternatives implementation : if any internal lexer matches, its result will
10
 * be returned.
11
 */
12
class Alternatives implements DateLexerInterface
13
{
14
    /**
15
     * Lexer list.
16
     *
17
     * @var array
18
     */
19
    protected $lexers = [];
20
21
    /**
22
     * Add a lexer.
23
     *
24
     * @param DateLexerInterface $lexer
25
     */
26
    public function addLexer(DateLexerInterface $lexer)
27
    {
28
        $this->lexers[] = $lexer;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function tokenizeDate($string, $offset = 0)
35
    {
36
        foreach ($this->lexers as $lexer) {
37
            if (null !== $res = $lexer->tokenizeDate($string, $offset)) {
38
                // A lexer failed to match : exit.
39
                return $res;
40
            }
41
        }
42
    }
43
}
44