Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 13 |
| Collection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 13 |
| addLexer | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| tokenizeDate | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 10 |
|||
| <?php | |
| namespace Popy\Calendar\Parser\DateLexer; | |
| use Popy\Calendar\Parser\DateLexerResult; | |
| use Popy\Calendar\Parser\DateLexerInterface; | |
| /** | |
| * Collection/Chain implementation : every contained lexer has to match its own | |
| * part, then the full result is returned. | |
| */ | |
| class Collection implements DateLexerInterface | |
| { | |
| /** | |
| * Lexer list. | |
| * | |
| * @var array | |
| */ | |
| protected $lexers = []; | |
| /** | |
| * Add a lexer. | |
| * | |
| * @param DateLexerInterface $lexer | |
| */ | |
| public function addLexer(DateLexerInterface $lexer) | |
| { | |
| $this->lexers[] = $lexer; | |
| } | |
| /** | |
| * @inheritDoc | |
| */ | |
| public function tokenizeDate($string, $offset = 0) | |
| { | |
| $result = new DateLexerResult($offset); | |
| foreach ($this->lexers as $lexer) { | |
| if (null === $res = $lexer->tokenizeDate($string, $result->getOffset())) { | |
| // A lexer failed to match : exit. | |
| return null; | |
| } | |
| $result->merge($res); | |
| } | |
| return $result; | |
| } | |
| } |