SortingTrait   A
last analyzed

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 Improved\IteratorPipeline\Traits;
6
7
use Improved 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 7
    public function sort($compare, bool $preserveKeys = true)
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::sort() return type has no value type specified in iterable type static(Improved\IteratorPipeline\Pipeline).
Loading history...
32
    {
33 7
        return $this->then("Improved\iterable_sort", $compare, $preserveKeys);
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::sort() should return static(Improved\IteratorPipeline\Pipeline) but returns Improved\IteratorPipeline\Pipeline.
Loading history...
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)
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::sortKeys() return type has no value type specified in iterable type static(Improved\IteratorPipeline\Pipeline).
Loading history...
43
    {
44 2
        return $this->then("Improved\iterable_sort_keys", $compare);
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::sortKeys() should return static(Improved\IteratorPipeline\Pipeline) but returns Improved\IteratorPipeline\Pipeline.
Loading history...
45
    }
46
47
    /**
48
     * Reverse order of elements of an iterable.
49
     *
50
     * @return static
51
     */
52 1
    public function reverse()
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::reverse() return type has no value type specified in iterable type static(Improved\IteratorPipeline\Pipeline).
Loading history...
53
    {
54 1
        return $this->then("Improved\iterable_reverse");
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::reverse() should return static(Improved\IteratorPipeline\Pipeline) but returns Improved\IteratorPipeline\Pipeline.
Loading history...
55
    }
56
}
57