FilterTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 14 2
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