Completed
Pull Request — master (#47)
by
unknown
09:17
created

Trim::filter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
/**
3
 * Particle.
4
 *
5
 * @link      http://github.com/particle-php for the canonical source repository
6
 * @copyright Copyright (c) 2005-2015 Particle (http://particle-php.com)
7
 * @license   https://github.com/particle-php/Filter/blob/master/LICENSE New BSD License
8
 */
9
namespace Particle\Filter\FilterRule;
10
11
use Particle\Filter\FilterRule;
12
13
/**
14
 * Class Trim
15
 *
16
 * @package Particle\Filter\FilterRule
17
 */
18
class Trim extends FilterRule
19
{
20
    /**
21
     * @var string|null
22
     */
23
    protected $characters;
24
25
    /**
26
     * Set characters to trim, if none are given, use the PHP default
27
     *
28
     * @param null|string $characters
29
     */
30 21
    public function __construct($characters = null)
31
    {
32 21
        $this->characters = $characters;
33 21
    }
34
35
    /**
36
     * Trim the value, if no characters to trim are given, use the PHP default
37
     *
38
     * @param mixed $value
39
     * @return string
40
     */
41 20
    public function filter($value)
42
    {
43 20
        if ($value === null) {
44 1
            return $value;
45
        }
46
47 19
        if ($this->characters === null) {
48 17
            return trim($value);
49
        }
50
51 2
        return trim($value, $this->characters);
52
    }
53
}
54