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

CaseSensitiveTrait::pushCaseSensitivityToContext()   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\Terminal;
4
5
use Vanderlee\Comprehend\Core\Context;
6
7
/**
8
 * Classes implementing this can scan
9
 *
10
 * @author Martijn
11
 */
12
trait CaseSensitiveTrait
13
{
14
15
    /**
16
     * @var boolean
17
     */
18
    private $caseSensitivity = null;
19
20
    private function pushCaseSensitivityToContext(Context $context)
21
    {
22
        if ($this->caseSensitivity !== null) {
23
            $context->pushCaseSensitivity($this->caseSensitivity);
24
        }
25
    }
26
27
    private function popCaseSensitivityFromContext(Context $context)
28
    {
29
        if ($this->caseSensitivity !== null) {
30
            $context->popCaseSensitivity();
31
        }
32
    }
33
34
    public function setCaseSensitivity(string $preference)
35
    {
36
        $this->caseSensitivity = $preference;
0 ignored issues
show
Documentation Bug introduced by
The property $caseSensitivity was declared of type boolean, but $preference is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
37
38
        return $this;
39
    }
40
41
    public function caseSensitive()
42
    {
43
        $this->caseSensitivity = true;
44
45
        return $this;
46
    }
47
48
    public function caseInsensitive()
49
    {
50
        $this->caseSensitivity = false;
51
52
        return $this;
53
    }
54
55
}
56