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

FilterByPredicate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A apply() 0 9 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