RemoveTrailingCharacters::__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
 * Remove trailing punctuation from words.
7
 */
8
class RemoveTrailingCharacters extends AbstractFilter implements FilterInterface
9
{
10
    protected $punctuation;
11
12
    /**
13
     * @param string[] $punctuation Array of punctuation to be removed.
14
     */
15 8
    public function __construct($punctuation = array('.', ',', ';', '?', '!', '{' , '}', '[', ']'))
16
    {
17 8
        $this->punctuation = $punctuation;
18 8
    }
19
20
    /** {@inheritdoc} */
21 15
    public function filterWord($word)
22
    {
23 15
        foreach($this->punctuation as $p) {
24 15
            if(substr($word, -1) == $p) {
25 15
                $word = substr($word, 0, -1);
26
            }
27
        }
28
29 15
        return $word;
30
    }
31
}