SliceTrait::slice()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 2
dl 0
loc 16
ccs 8
cts 8
cp 1
crap 5
rs 9.4222
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Itertools\lib\Traits;
7
8
use Zicht\Itertools\lib\SliceIterator;
9
10
trait SliceTrait
11
{
12
    /**
13
     * TODO: document!
14
     *
15
     * @param int $start
16
     * @param null|int $end
17
     * @return SliceIterator
18
     */
19 31
    public function slice($start, $end = null)
20
    {
21 31
        if (!is_int($start)) {
22 3
            throw new \InvalidArgumentException('Argument $start must be an integer');
23
        }
24
25 28
        if (!(is_null($end) || is_int($end))) {
26 2
            throw new \InvalidArgumentException('Argument $end must be an integer or null');
27
        }
28
29 26
        if ($this instanceof \Iterator) {
30 25
            return new SliceIterator($this, $start, $end);
31
        }
32
33 1
        return null;
34
    }
35
}
36