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

SortingTrait::reverse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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