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

SkipOperation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A apply() 16 16 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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