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

Collections   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 16
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A sort() 0 6 1
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