Collections   A
last analyzed

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