UniqueTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A unique() 0 11 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\UniqueIterator;
10
11
trait UniqueTrait
12
{
13
    /**
14
     * Returns an iterator where the values from $strategy are unique
15
     *
16
     * The $strategy is used to get values for every element in this iterable,
17
     * when this value has already been encountered the element is not
18
     * part of the returned iterator
19
     *
20
     * > iter\iterable([1, 1, 2, 2, 3, 3])->unique()
21
     * 1 2 3
22
     *
23
     * > iter\iterable([['id' => 1, 'value' => 'a'], ['id' => 1, 'value' => 'b']])->unique('id')
24
     * ['id' => 1, 'value' => 'a']  # one element in this list
25
     *
26
     * @param null|string|\Closure $strategy
27
     * @return UniqueIterator
28
     */
29 19
    public function unique($strategy = null)
30
    {
31 19
        if ($this instanceof \Iterator) {
32 18
            return new UniqueIterator(
33 18
                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...
34 15
                $this
35
            );
36
        }
37
38 1
        return null;
39
    }
40
}
41