Passed
Push — master ( 9a224a...3e0fbd )
by Sebastian
02:02
created

Collections::sort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (C) 2016 Sebastian Böttger <[email protected]>
4
 * You may use, distribute and modify this code under the
5
 * terms of the MIT license.
6
 *
7
 * You should have received a copy of the MIT license with
8
 * this file. If not, please visit: https://opensource.org/licenses/mit-license.php
9
 */
10
11
namespace Seboettg\Collection;
12
13
use Seboettg\Collection\Comparable\Comparator;
14
15
16
/**
17
 * Class Collections
18
 * @package Seboettg\Collection
19
 *
20
 * @author Sebastian Böttger <[email protected]>
21
 */
22
class Collections
23
{
24
    /**
25
     * Sorts the specified list according to the order induced by the specified comparator. All elements in the list
26
     * must be mutually comparable.
27
     *
28
     * @param ArrayList $list
29
     * @param Comparator $comparator
30
     * @return ArrayList
31
     */
32 3
    public static function sort(ArrayList &$list, Comparator $comparator)
33
    {
34 3
        $array = $list->toArray();
35 3
        usort($array, [$comparator, "compare"]);
36 3
        $list->replace($array);
37 3
        return $list;
38
    }
39
}
40