Completed
Push — master ( 2fcf3b...8f00bb )
by Rick
04:45 queued 02:17
created

Cut   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 37
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A filter() 0 8 2
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 4
    public function __construct($start, $length = null)
35
    {
36 4
        $this->start = $start;
37 4
        $this->length = $length;
38 4
    }
39
40
    /**
41
     * Cuts the given value
42
     *
43
     * @param mixed $value
44
     * @return string
45
     */
46 4
    public function filter($value)
47
    {
48 4
        if ($this->encodingFormat !== null) {
49 2
            return mb_substr($value, $this->start, $this->length, $this->encodingFormat);
50
        }
51
52 2
        return mb_substr($value, $this->start, $this->length);
53
    }
54
}
55