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

CaseSensitiveTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A caseSensitive() 0 5 1
A caseInsensitive() 0 5 1
A popCaseSensitivityFromContext() 0 4 2
A setCaseSensitivity() 0 5 1
A pushCaseSensitivityToContext() 0 4 2
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