Not::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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