Completed
Push — master ( c80620...0cd8d9 )
by Martijn
03:25
created

Not::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Vanderlee\Comprehend\Parser\Structure;
4
5
use Vanderlee\Comprehend\Core\ArgumentsTrait;
6
use Vanderlee\Comprehend\Core\Context;
7
use Vanderlee\Comprehend\Parser\Parser;
8
9
/**
10
 * Description of NotParser
11
 *
12
 * @author Martijn
13
 */
14
class Not extends Parser
15
{
16
17
    use ArgumentsTrait;
18
19
    private $parser = null;
20
21
    public function __construct($parser)
22
    {
23
        $this->parser = self::getArgument($parser);
24
    }
25
26
    protected function parse(&$input, $offset, Context $context)
27
    {
28
        $match = $this->parser->parse($input, $offset, $context);
29
        return $match->match ? $this->failure($input, $offset, $match->length) : $this->success($input, $offset, 0);
30
    }
31
32
    public function __toString()
33
    {
34
        return '!' . $this->parser;
35
    }
36
37
}
38