RemoveCharacters::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
ccs 5
cts 5
cp 1
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace SixtyNine\Cloud\Filters;
4
5
/**
6
 * Remove unwanted characters from words.
7
 */
8
class RemoveCharacters extends AbstractFilter implements FilterInterface
9
{
10
    protected $unwantedCharacters;
11
12
    /**
13
     * @param array $unwantedCharacters Array of characters to be removed.
14
     */
15 8
    public function __construct($unwantedCharacters = null)
16
    {
17 8
        if (!$unwantedCharacters) {
18
            $unwantedCharacters = array(
19 8
                ':', '?', '!', '\'', '"', '(', ')', '[', ']',
20
            );
21
        }
22 8
        $this->unwantedCharacters = $unwantedCharacters;
23 8
    }
24
25
    /** {@inheritdoc} */
26 11
    public function filterWord($word)
27
    {
28 11
        foreach($this->unwantedCharacters as $p) {
29 11
            $word = str_replace($p, '', $word);
30
        }
31
32 11
        return $word;
33
    }
34
}