FilterTrait::filter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 2
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Itertools\lib\Traits;
7
8
use Zicht\Itertools\conversions;
9
use Zicht\Itertools\lib\FilterIterator;
10
11
trait FilterTrait
12
{
13
    /**
14
     * Make an iterator that returns values from this iterable where the
15
     * $strategy determines that the values are not empty.
16
     *
17
     * @param null|string|\Closure $strategy Optional, when not specified !empty will be used
18
     * @return FilterIterator
19
     */
20 7
    public function filter($strategy = null)
21
    {
22 7
        if ($this instanceof \Iterator) {
23 6
            $strategy = conversions\mixed_to_value_getter($strategy);
0 ignored issues
show
Deprecated Code introduced by
The function Zicht\Itertools\conversi...mixed_to_value_getter() has been deprecated with message: Use \Zicht\Itertools\util\Conversions::mixedToClosure, will be removed in version 3.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
24 5
            $isValid = function ($value, $key) use ($strategy) {
25 3
                $tempVarPhp54 = $strategy($value, $key);
26 3
                return !empty($tempVarPhp54);
27 5
            };
28
29 5
            return new FilterIterator($isValid, $this);
30
        }
31
32 1
        return null;
33
    }
34
}
35