Total Complexity | 6 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class All extends Parser |
||
15 | { |
||
16 | |||
17 | use ArgumentsTrait; |
||
18 | |||
19 | /** |
||
20 | * @var Parser[] |
||
21 | */ |
||
22 | private $parsers = []; |
||
23 | |||
24 | public function __construct(...$arguments) |
||
25 | { |
||
26 | if (count($arguments) < 2) { |
||
27 | throw new \InvalidArgumentException('Less than 2 arguments provided'); |
||
28 | } |
||
29 | $this->parsers = self::getArguments($arguments); |
||
30 | } |
||
31 | |||
32 | protected function parse(&$input, $offset, Context $context) |
||
33 | { |
||
34 | $length = PHP_INT_MAX; |
||
35 | foreach ($this->parsers as $parser) { |
||
36 | $match = $parser->parse($input, $offset, $context); |
||
37 | $length = min($length, $match->length); |
||
38 | if (!$match->match) { |
||
39 | return $this->failure($input, $offset, $length); |
||
40 | } |
||
41 | } |
||
42 | return $this->success($input, $offset, $length); |
||
43 | } |
||
44 | |||
45 | public function __toString() |
||
48 | } |
||
49 | |||
50 | } |
||
51 |