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

Cut::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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