CaseSensitiveContextTrait::handleCase()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 1
f 0
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