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

SliceTrait::slice()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

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