Completed
Push — master ( 256c3c...d8e20a )
by Karsten
01:47
created

FilterByPredicate::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
crap 1
1
<?php
2
/**
3
 * File was created 06.05.2015 16:25
4
 *
5
 * @author Karsten J. Gerber <[email protected]>
6
 */
7
8
namespace PeekAndPoke\Component\Psi\Operation\Intermediate\Predicate;
9
10
use PeekAndPoke\Component\Psi\BinaryFunction;
11
use PeekAndPoke\Component\Psi\UnaryFunction;
12
13
/**
14
 * @author Karsten J. Gerber <[email protected]>
15
 */
16
class FilterByPredicate extends AbstractPredicateOperation
17
{
18
    /** @var callable|\Closure|BinaryFunction|UnaryFunction */
19
    private $mapper;
20
21
    /**
22
     * FilterByPredicate constructor.
23
     *
24
     * @param callable|\Closure|BinaryFunction|UnaryFunction $mapper
25
     * @param callable|\Closure|BinaryFunction|UnaryFunction $condition
26
     */
27 2
    public function __construct($mapper, $condition)
28
    {
29 2
        parent::__construct($condition);
30 2
        $this->mapper = $mapper;
31 2
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function apply($input, $index, &$useItem, &$canContinue)
37
    {
38 2
        $mapper = $this->mapper;
39
40 2
        $useItem     = $this->test($mapper($input), $index);
41 2
        $canContinue = true;
42
43 2
        return $input;
44
    }
45
}
46