Completed
Push — master ( 2097d9...6577e3 )
by Antonio Carlos
01:41
created

CharCase::mixedcase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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