SliceTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A slice() 0 16 5
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