ChangeCase::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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