CharCase::changeCase()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
namespace PragmaRX\Random;
4
5
trait CharCase
6
{
7
    protected $lowercase = false;
8
9
    protected $uppercase = false;
10
11
    /**
12
     * Get lowercase state.
13
     *
14
     * @return bool
15
     */
16 12
    public function isLowercase()
17
    {
18 12
        return $this->lowercase;
19
    }
20
21
    /**
22
     * Get uppercase state.
23
     *
24
     * @return bool
25
     */
26 10
    public function isUppercase()
27
    {
28 10
        return $this->uppercase;
29
    }
30
31
    /**
32
     * Return a string in the proper case.
33
     *
34
     * @param $string
35
     * @return string
36
     */
37 12
    protected function changeCase($string)
38
    {
39 12
        if ($this->isLowercase()) {
40 4
            return strtolower($string);
41
        }
42
43 10
        if ($this->isUppercase()) {
44 2
            return strtoupper($string);
45
        }
46
47 9
        return $string;
48
    }
49
50
    /**
51
     * Set the lowercase state.
52
     *
53
     * @param $state
54
     * @return $this
55
     */
56 4
    public function lowercase($state = true)
57
    {
58 4
        $this->mixedcase()->lowercase = $state;
59
60 4
        return $this;
61
    }
62
63
    /**
64
     * Set the uppercase state.
65
     *
66
     * @param $state
67
     * @return $this
68
     * @internal param bool $uppercase
69
     */
70 4
    public function uppercase($state = true)
71
    {
72 4
        $this->mixedcase()->uppercase = $state;
73
74 4
        return $this;
75
    }
76
77
    /**
78
     * Set case to mixed.
79
     *
80
     * @return $this
81
     */
82 5
    public function mixedcase()
83
    {
84 5
        $this->uppercase = false;
85
86 5
        $this->lowercase = false;
87
88 5
        return $this;
89
    }
90
}
91