PreferTrait::popPreferenceFromContext()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
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\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
     * Parser used for scanning the text.
18
     *
19
     * @var Parser
20
     */
21
    private $preference = null;
22
23 104
    private function pushPreferenceToContext(Context $context)
24
    {
25 104
        if ($this->preference) {
26 36
            $context->pushPreference($this->preference);
27
        }
28 104
    }
29
30 104
    private function popPreferenceFromContext(Context $context)
31
    {
32 104
        if ($this->preference) {
33 36
            $context->popPreference();
34
        }
35 104
    }
36
37
    /**
38
     * @param string $preference
39
     *
40
     * @return $this
41
     */
42 1
    public function setPreference($preference)
43
    {
44 1
        $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...
45
46 1
        return $this;
47
    }
48
49 1
    public function preferShortest()
50
    {
51 1
        $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...
52
53 1
        return $this;
54
    }
55
56 2
    public function preferLongest()
57
    {
58 2
        $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...
59
60 2
        return $this;
61
    }
62
63 1
    public function preferFirst()
64
    {
65 1
        $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...
66
67 1
        return $this;
68
    }
69
}
70