FilterByPredicate::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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