ChangeCase::filterWord()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
ccs 12
cts 12
cp 1
cc 4
nc 4
nop 1
crap 4
1
<?php
2
3
namespace SixtyNine\Cloud\Filters;
4
5
/**
6
 * Change the case of the words.
7
 */
8
class ChangeCase extends AbstractFilter implements FilterInterface
9
{
10
    const UPPERCASE = 'uppercase';
11
    const LOWERCASE = 'lowercase';
12
    const UCFIRST = 'ucfirst';
13
14
    /** @var string */
15
    protected $case;
16
17
    /**
18
     * @param string $case
19
     */
20 1
    public function __construct($case)
21
    {
22 1
        $this->case = $case;
23 1
    }
24
25
    /** {@inheritdoc} */
26 3
    public function filterWord($word)
27
    {
28 3
        switch ($this->case) {
29 3
            case self::UPPERCASE:
30 1
                $word = strtoupper($word);
31 1
                break;
32 2
            case self::UCFIRST:
33 1
                $word = ucfirst($word);
34 1
                break;
35 1
            case self::LOWERCASE:
36 1
                $word = strtolower($word);
37 1
                break;
38
        }
39
40 3
        return $word;
41
    }
42
}