CycleTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A cycle() 0 8 2
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