Failed Conditions
Push — master ( dcb275...c3bea1 )
by Arnold
02:34
created

SortingTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 43
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sort() 0 3 1
A reverse() 0 3 1
A sortKeys() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ipl\IteratorPipeline\Traits;
6
7
use Ipl as i;
8
9
/**
10
 * Methods that change the order of the elements.
11
 */
12
trait SortingTrait
13
{
14
    /**
15
     * Define the next step via a callback that returns an array or Traversable object.
16
     *
17
     * @param callable $callback
18
     * @param mixed    ...$args
19
     * @return static
20
     */
21
    abstract public function then(callable $callback, ...$args);
22
23
24
    /**
25
     * Sort all elements of an iterator.
26
     *
27
     * @param callable|int $compare       SORT_* flags as binary set or callback comparator function
28
     * @param bool         $preserveKeys
29
     * @return static
30
     */
31 4
    public function sort($compare, bool $preserveKeys = true)
32
    {
33 4
        return $this->then(i\iterable_sort, $compare, $preserveKeys);
34
    }
35
36
    /**
37
     * Sort all elements of an iterator based on the key.
38
     *
39
     * @param callable|int $compare   SORT_* flags as binary set or callback comparator function
40
     * @return static
41
     */
42 2
    public function sortKeys($compare)
43
    {
44 2
        return $this->then(i\iterable_sort_keys, $compare);
45
    }
46
47
    /**
48
     * Reverse order of elements of an iterable.
49
     *
50
     * @return static
51
     */
52 1
    public function reverse()
53
    {
54 1
        return $this->then(i\iterable_reverse);
55
    }
56
}
57