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

PreferTrait::pushPreferenceToContext()   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 1
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\Context;
6
use Vanderlee\Comprehend\Directive\Prefer;
7
use Vanderlee\Comprehend\Parser\Parser;
8
9
/**
10
 * Classes implementing this can scan
11
 *
12
 * @author Martijn
13
 */
14
trait PreferTrait
15
{
16
17
    /**
18
     * Parser used for scanning the text
19
     * @var Parser
20
     */
21
    private $preference = null;
22
23
    private function pushPreferenceToContext(Context $context)
24
    {
25
        if ($this->preference) {
26
            $context->pushPreference($this->preference);
27
        }
28
    }
29
30
    private function popPreferenceFromContext(Context $context)
31
    {
32
        if ($this->preference) {
33
            $context->popPreference();
34
        }
35
    }
36
37
    public function setPreference(string $preference)
38
    {
39
        $this->preference = $preference;
0 ignored issues
show
Documentation Bug introduced by
It seems like $preference of type string is incompatible with the declared type Vanderlee\Comprehend\Parser\Parser of property $preference.

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...
40
41
        return $this;
42
    }
43
44
    public function preferShortest()
45
    {
46
        $this->preference = Prefer::SHORTEST;
0 ignored issues
show
Documentation Bug introduced by
It seems like Vanderlee\Comprehend\Directive\Prefer::SHORTEST of type string is incompatible with the declared type Vanderlee\Comprehend\Parser\Parser of property $preference.

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...
47
48
        return $this;
49
    }
50
51
    public function preferLongest()
52
    {
53
        $this->preference = Prefer::LONGEST;
0 ignored issues
show
Documentation Bug introduced by
It seems like Vanderlee\Comprehend\Directive\Prefer::LONGEST of type string is incompatible with the declared type Vanderlee\Comprehend\Parser\Parser of property $preference.

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...
54
55
        return $this;
56
    }
57
58
    public function preferFirst()
59
    {
60
        $this->preference = Prefer::FIRST;
0 ignored issues
show
Documentation Bug introduced by
It seems like Vanderlee\Comprehend\Directive\Prefer::FIRST of type string is incompatible with the declared type Vanderlee\Comprehend\Parser\Parser of property $preference.

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...
61
62
        return $this;
63
    }
64
65
}
66