IteratorFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A reverseSequence() 0 9 2
A directSequence() 0 9 2
1
<?php
2
/**
3
 * @author Maxim Sokolovsky
4
 */
5
6
namespace WS\Utils\Collections\Iterator;
7
8
class IteratorFactory
9
{
10 5
    public static function directSequence($length): Iterator
11
    {
12 5
        $current = 0;
13
        return new CallbackIterator(static function () use (& $current, $length) {
14 5
            if ($current === $length) {
15 3
                return (new IterateResult())->setAsRunOut();
16
            }
17
18 5
            return (new IterateResult())->setValue($current++);
19 5
        });
20
    }
21
22 5
    public static function reverseSequence($length): Iterator
23
    {
24 5
        $current = $length - 1;
25
        return new CallbackIterator(static function () use (& $current) {
26 5
            if ($current === -1) {
27 3
                return (new IterateResult())->setAsRunOut();
28
            }
29
30 5
            return (new IterateResult())->setValue($current--);
31 5
        });
32
    }
33
}
34