Cut   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 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-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 Cut
15
 *
16
 * @package Particle\Filter\FilterRule
17
 */
18
class Cut extends FilterRule
19
{
20
    /**
21
     * @var int
22
     */
23
    private $start;
24
25
    /**
26
     * @var int|null
27
     */
28
    private $length;
29
30
    /**
31
     * @param int       $start
32
     * @param int|null  $length
33
     */
34 5
    public function __construct($start, $length = null)
35
    {
36 5
        $this->start = $start;
37 5
        $this->length = $length;
38 5
    }
39
40
    /**
41
     * Cuts the given value
42
     *
43
     * @param mixed $value
44
     * @return string
45
     */
46 5
    public function filter($value)
47
    {
48 5
        if (!is_string($value)) {
49 1
            return $value;
50
        }
51
52 4
        if ($this->encodingFormat !== null) {
53 2
            return mb_substr($value, $this->start, $this->length, $this->encodingFormat);
54
        }
55
56 2
        return mb_substr($value, $this->start, $this->length);
57
    }
58
}
59