Collections::sort()   A
last analyzed

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
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