Passed
Push — master ( ad1515...9a224a )
by Sebastian
01:48
created

Collections::sort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 2
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
    public static function sort(ArrayList &$list, Comparator $comparator)
33
    {
34
        $array = $list->toArray();
35
        usort($array, [$comparator, "compare"]);
36
        $list->replace($array);
37
        return $list;
38
    }
39
}
40