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

SpacingTrait::spacing()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 1
dl 0
loc 11
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
 * Classes implementing this can scan
11
 *
12
 * @author Martijn
13
 */
14
trait SpacingTrait
15
{
16
17
    use ArgumentsTrait;
18
19
    /**
20
     * Parser used for scanning the text
21
     * @var Parser
22
     */
23
    private $spacer = false;
24
25
    private function pushSpacer(Context $context)
26
    {
27
        if ($this->spacer !== false) {
0 ignored issues
show
introduced by
The condition $this->spacer is always true. If $this->spacer can have other possible types, add them to src/Parser/Structure/SpacingTrait.php:20
Loading history...
28
            $context->pushSpacer($this->spacer);
29
        }
30
    }
31
32
    private function popSpacer(Context $context)
33
    {
34
        if ($this->spacer !== false) {
0 ignored issues
show
introduced by
The condition $this->spacer is always true. If $this->spacer can have other possible types, add them to src/Parser/Structure/SpacingTrait.php:20
Loading history...
35
            $context->popSpacer();
36
        }
37
    }
38
39
    /**
40
     * Set a spacing parser for this parser or disable or enable (if a previous
41
     * spacing parser is enabled) spacing parsing.
42
     *
43
     * @param Parser|bool|null $spacer
44
     * @return $this
45
     */
46
    public function spacing($spacer = true)
47
    {
48
        if ($spacer === true) {
49
            $this->spacer = true;
0 ignored issues
show
Documentation Bug introduced by
It seems like true of type true is incompatible with the declared type Vanderlee\Comprehend\Parser\Parser of property $spacer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
        } elseif ($spacer === null || $spacer === false) {
0 ignored issues
show
introduced by
The condition $spacer === false is always true.
Loading history...
51
            $this->spacer = null;
52
        } else {
53
            $this->spacer = self::getArgument($spacer);
54
        }
55
56
        return $this;
57
    }
58
59
}
60