SortingTrait::shuffle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
ccs 0
cts 4
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Nip\Collections\Traits;
4
5
/**
6
 * Class SortingTrait
7
 * @package Nip\Collections\Traits
8
 */
9
trait SortingTrait
10
{
11
    /**
12
     * @return mixed
13
     */
14 1
    public function end()
15
    {
16 1
        $this->index = count($this->items);
0 ignored issues
show
Bug Best Practice introduced by
The property index does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17 1
        return end($this->items);
18
    }
19
20
    /**
21
     * @return mixed
22
     */
23
    public function current()
24
    {
25
        return current($this->items);
26
    }
27
28
    /**
29
     * @return mixed
30
     */
31 1
    public function next()
32
    {
33 1
        $this->index++;
34 1
        return next($this->items);
35
    }
36
    /**
37
     * @return mixed
38
     */
39 2
    public function rewind()
40
    {
41 2
        $this->index = 0;
0 ignored issues
show
Bug Best Practice introduced by
The property index does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
42
43 2
        return reset($this->items);
44
    }
45
46
    /**
47
     * @return $this
48
     */
49
    public function ksort()
50
    {
51
        ksort($this->items);
52
        $this->rewind();
53
        return $this;
54
    }
55
56
    /**
57
     * @param $callback
58
     * @return $this
59
     */
60
    public function usort($callback)
61
    {
62
        usort($this->items, $callback);
63
        $this->rewind();
64
        return $this;
65
    }
66
67
    /**
68
     * @param $callback
69
     * @return $this
70
     */
71
    public function uasort($callback)
72
    {
73
        uasort($this->items, $callback);
74
        $this->rewind();
75
        return $this;
76
    }
77
78
    /**
79
     * @return $this
80
     */
81
    public function shuffle()
82
    {
83
        shuffle($this->items);
84
        $this->rewind();
85
        return $this;
86
    }
87
}
88