Passed
Pull Request — master (#2)
by Sebastian
02:16
created

Collections::sort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Seboettg\Collection;
4
5
6
/**
7
 * Class Collections
8
 * @package Seboettg\Collection
9
 *
10
 * @author Sebastian Böttger <[email protected]>
11
 */
12
class Collections
13
{
14
    /**
15
     * Sorts the specified list according to the order induced by the specified comparator. All elements in the list
16
     * must be mutually comparable.
17
     *
18
     * @param ArrayList $list
19
     * @param Comparator $comparator
20
     * @return ArrayList
21
     */
22
    public static function sort(ArrayList &$list, Comparator $comparator)
23
    {
24
        $array = $list->toArray();
25
        usort($array, [$comparator, "compare"]);
26
        $list->replace($array);
27
        return $list;
28
    }
29
}
30