Sequence   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 46
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A pickNext() 0 7 1
A pickFirst() 0 7 1
1
<?php
2
/**
3
 * This file is part of Zee Project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @see https://github.com/zee/
9
 */
10
11
declare(strict_types=1);
12
13
namespace Zee\Chains;
14
15
/**
16
 * Chain iterable sequence.
17
 */
18
final class Sequence
19
{
20
    /**
21
     * @var int
22
     */
23
    private $pointer = 0;
24
25
    /**
26
     * @var Chain
27
     */
28
    private $chain;
29
30
    /**
31
     * @param Chain $chain
32
     */
33 2
    public function __construct(Chain $chain)
34
    {
35 2
        $this->chain = $chain;
36 2
    }
37
38
    /**
39
     * Changes pointer to next stage.
40
     *
41
     * @return Handler
42
     */
43 2
    public function pickNext(): Handler
44
    {
45 2
        ++$this->pointer;
46 2
        $handler = $this->chain->pick($this->pointer);
47
48 2
        return $handler;
49
    }
50
51
    /**
52
     * Rewinds sequence and returns first handler.
53
     *
54
     * @return Handler
55
     */
56 2
    public function pickFirst(): Handler
57
    {
58 2
        $this->pointer = 0;
59 2
        $handler = $this->chain->pick($this->pointer);
60
61 2
        return $handler;
62
    }
63
}
64