Completed
Push — master ( aeb3a4...04afb5 )
by brian
01:57
created

MatchedPreferenceSort::sortAscending()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4286
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * @copyright   (c) 2006-present brian ridley
5
 * @author      brian ridley <[email protected]>
6
 * @license     http://opensource.org/licenses/MIT MIT
7
 */
8
9
namespace ptlis\ConNeg\Preference\Matched;
10
11
/**
12
 * Helper class encoding the rules governing the sorting of MatchedPreferenceCollections.
13
 */
14
class MatchedPreferenceSort
15
{
16
    /**
17
     * Sort the array of MatchedPreference instances in ascending order.
18
     *
19
     * @param MatchedPreferenceInterface[] $prefList
20
     *
21
     * @return MatchedPreferenceInterface[]
22
     */
23 7
    public function sortAscending(array $prefList)
24
    {
25 7
        $comparator = new MatchedPreferenceComparator();
26
27 7
        usort(
28 7
            $prefList,
29
            function (MatchedPreferenceInterface $lValue, MatchedPreferenceInterface $rValue) use ($comparator) {
30 7
                return -1 * $comparator->compare($lValue, $rValue);
31
            }
32 7
        );
33
34 7
        return $prefList;
35
    }
36
37
    /**
38
     * Sort the array of MatchedPreference instances in descending order.
39
     *
40
     * @param MatchedPreferenceInterface[] $prefList
41
     *
42
     * @return MatchedPreferenceInterface[]
43
     */
44 77
    public function sortDescending(array $prefList)
45
    {
46 77
        $comparator = new MatchedPreferenceComparator();
47
48 77
        usort(
49 77
            $prefList,
50 68
            function (MatchedPreferenceInterface $lValue, MatchedPreferenceInterface $rValue) use ($comparator) {
51 68
                return $comparator->compare($lValue, $rValue);
52
            }
53 77
        );
54
55 77
        return $prefList;
56
    }
57
}
58