Trim   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filter() 0 12 3
1
<?php
2
/**
3
 * Particle.
4
 *
5
 * @link      http://github.com/particle-php for the canonical source repository
6
 * @copyright Copyright (c) 2005-2016 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 22
    public function __construct($characters = null)
31
    {
32 22
        $this->characters = $characters;
33 22
    }
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 21
    public function filter($value)
42
    {
43 21
        if (!is_string($value)) {
44 2
            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