CycleTrait::cycle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 10
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\CycleIterator;
9
10
trait CycleTrait
11
{
12
    /**
13
     * Make an iterator returning elements from this iterable and saving a
14
     * copy of each.  When the iterable is exhausted, return elements from
15
     * the saved copy.  Repeats indefinitely.
16
     *
17
     * > iterable('ABCD')->cycle()
18
     * A B C D A B C D A B C D ...
19
     *
20
     * @return CycleIterator
21
     */
22 11
    public function cycle()
23
    {
24 11
        if ($this instanceof \Iterator) {
25 10
            return new CycleIterator($this);
26
        }
27
28 1
        return null;
29
    }
30
}
31