Passed
Push — master ( 9e9b54...8c04f5 )
by
unknown
38s
created

SliceTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B slice() 0 16 5
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib\Traits;
8
9
use Zicht\Itertools\lib\SliceIterator;
10
11
trait SliceTrait
12
{
13
    /**
14
     * TODO: document!
15
     *
16
     * @param integer $start
17
     * @param null|integer $end
18
     * @return SliceIterator
19
     */
20 31
    public function slice($start, $end = null)
21
    {
22 31
        if (!is_int($start)) {
23 3
            throw new \InvalidArgumentException('Argument $start must be an integer');
24
        }
25
26 28
        if (!(is_null($end) || is_int($end))) {
27 2
            throw new \InvalidArgumentException('Argument $end must be an integer or null');
28
        }
29
30 26
        if ($this instanceof \Iterator) {
31 25
            return new SliceIterator($this, $start, $end);
32
        }
33
34 1
        return null;
35
    }
36
}
37