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

Space   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A parse() 0 7 1
A __toString() 0 3 1
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
    public function __construct($spacer, $parser)
36
    {
37
        $this->spacer = $spacer === null ? null : self::getArgument($spacer);
38
        $this->parser = self::getArgument($parser);
39
    }
40
41
    protected function parse(&$input, $offset, Context $context)
42
    {
43
        $context->pushSpacer($this->spacer);
44
        $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

44
        /** @scrutinizer ignore-call */ 
45
        $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...
45
        $context->popSpacer();
46
47
        return $match;
48
    }
49
50
    public function __toString()
51
    {
52
        return (string)$this->parser;
53
    }
54
55
}
56