Code Duplication    Length = 37-37 lines in 2 locations

src/Operation/Intermediate/Functional/LimitOperation.php 1 location

@@ 16-52 (lines=37) @@
13
 *
14
 * @author Karsten J. Gerber <[email protected]>
15
 */
16
class LimitOperation implements IntermediateOperation
17
{
18
    /** @var int */
19
    private $limit;
20
21
    /**
22
     * @param int $limit
23
     */
24
    public function __construct($limit)
25
    {
26
        $this->limit = $limit;
27
    }
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
    public function apply($input, $index, IntermediateContext $context)
37
    {
38
        if (! $context->memory->contains($this)) {
39
            $context->memory->offsetSet($this, 0);
40
        }
41
42
        $count = $context->memory->offsetGet($this);
43
        $context->memory->offsetSet($this, $count+1);
44
45
        $takeIt = $count < $this->limit;
46
47
        $context->outUseItem     = $takeIt;
48
        $context->outCanContinue = $takeIt;
49
50
        return $input;
51
    }
52
}
53

src/Operation/Intermediate/Functional/SkipOperation.php 1 location

@@ 16-52 (lines=37) @@
13
 *
14
 * @author Karsten J. Gerber <[email protected]>
15
 */
16
class SkipOperation implements IntermediateOperation
17
{
18
    /** @var int */
19
    private $skip;
20
21
    /**
22
     * @param int $skip
23
     */
24
    public function __construct($skip)
25
    {
26
        $this->skip = $skip;
27
    }
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
    public function apply($input, $index, IntermediateContext $context)
37
    {
38
        if (! $context->memory->contains($this)) {
39
            $context->memory->offsetSet($this, 0);
40
        }
41
42
        $count = $context->memory->offsetGet($this);
43
        $context->memory->offsetSet($this, $count+1);
44
45
        $takeIt = $count >= $this->skip;
46
47
        $context->outUseItem     = $takeIt;
48
        $context->outCanContinue = true;
49
50
        return $input;
51
    }
52
}
53