Completed
Push — master ( b69bd3...8db10c )
by Karsten
01:49
created

SkipOperation::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 3
crap 2
1
<?php
2
/**
3
 * Created by gerk on 02.12.17 10:34
4
 */
5
6
namespace PeekAndPoke\Component\Psi\Operation\Intermediate\Functional;
7
8
use PeekAndPoke\Component\Psi\IntermediateOperation;
9
use PeekAndPoke\Component\Psi\Solver\IntermediateContext;
10
11
/**
12
 *
13
 *
14
 * @author Karsten J. Gerber <[email protected]>
15
 */
16 View Code Duplication
class SkipOperation implements IntermediateOperation
17
{
18
    /** @var int */
19
    private $skip;
20
21
    /**
22
     * @param int $skip
23
     */
24 2
    public function __construct($skip)
25
    {
26 2
        $this->skip = $skip;
27 2
    }
28
29
    /**
30
     * @param mixed               $input   The element in the stream
31
     * @param mixed               $index   The index in the input iterator
32
     * @param IntermediateContext $context The solving context
33
     *
34
     * @return mixed
35
     */
36 2
    public function apply($input, $index, IntermediateContext $context)
37
    {
38 2
        if (! $context->memory->contains($this)) {
39 2
            $context->memory->offsetSet($this, 0);
40
        }
41
42 2
        $count = $context->memory->offsetGet($this);
43 2
        $context->memory->offsetSet($this, $count+1);
44
45 2
        $takeIt = $count >= $this->skip;
46
47 2
        $context->outUseItem     = $takeIt;
48 2
        $context->outCanContinue = true;
49
50 2
        return $input;
51
    }
52
}
53