CaseSensitiveContextTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 8
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10
c 1
b 1
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handleCase() 0 5 2
A pushCaseSensitivity() 0 3 1
A isCaseSensitive() 0 3 1
A popCaseSensitivity() 0 3 1
1
<?php
2
3
namespace Vanderlee\Comprehend\Core\Context;
4
5
trait CaseSensitiveContextTrait
6
{
7
    private $caseSensitivity = [];
8
9 513
    public function pushCaseSensitivity($caseSensitive = true)
10
    {
11 513
        $this->caseSensitivity[] = (bool)$caseSensitive;
12 513
    }
13
14 35
    public function popCaseSensitivity()
15
    {
16 35
        return array_pop($this->caseSensitivity);
17
    }
18
19 481
    public function isCaseSensitive()
20
    {
21 481
        return end($this->caseSensitivity);
22
    }
23
24
    // Helper
25 428
    public function handleCase($text)
26
    {
27 428
        return $this->isCaseSensitive()
28 400
            ? $text
29 428
            : mb_strtolower($text);
30
    }
31
}
32