Passed
Push — master ( 3a32ec...04e24a )
by Martijn
02:33
created

Space::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Vanderlee\Comprehend\Directive;
4
5
use Vanderlee\Comprehend\Core\ArgumentsTrait;
6
use Vanderlee\Comprehend\Core\Context;
7
use Vanderlee\Comprehend\Parser\Parser;
8
9
/**
10
 * Description of LexemeDirective
11
 *
12
 * @author Martijn
13
 */
14
class Space extends Parser
15
{
16
17
    use ArgumentsTrait;
18
19
    /**
20
     * @var null|Parser
21
     */
22
    private $spacer = null;
23
24
    /**
25
     * @var null|Parser
26
     */
27
    private $parser = null;
28
29
    /**
30
     * Set (or disable) a spacer for the parser
31
     *
32
     * @param Parser|string|int|bool|null $spacer
33
     * @param Parser|string|int $parser
34
     */
35 1
    public function __construct($spacer, $parser)
36
    {
37 1
        $this->spacer = $spacer === null
38
            ? null
39 1
            : self::getArgument($spacer);
40 1
        $this->parser = self::getArgument($parser);
41 1
    }
42
43 22
    protected function parse(&$input, $offset, Context $context)
44
    {
45 22
        $context->pushSpacer($this->spacer);
46 22
        $match = $this->parser->parse($input, $offset, $context);
0 ignored issues
show
Bug introduced by
The method parse() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        /** @scrutinizer ignore-call */ 
47
        $match = $this->parser->parse($input, $offset, $context);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47 22
        $context->popSpacer();
48
49 22
        return $match;
50
    }
51
52 22
    public function __toString()
53
    {
54 22
        return (string)$this->parser;
55
    }
56
57
}
58