RemoveTrailingCharacters   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filterWord() 0 10 3
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
}