MatchedPreferenceSort::sortAscending()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 12
ccs 8
cts 8
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 7
            function (MatchedPreferenceInterface $lValue, MatchedPreferenceInterface $rValue) use ($comparator) {
30 7
                return -1 * $comparator->compare($lValue, $rValue);
31 7
            }
32
        );
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 77
            function (MatchedPreferenceInterface $lValue, MatchedPreferenceInterface $rValue) use ($comparator) {
51 68
                return $comparator->compare($lValue, $rValue);
52 77
            }
53
        );
54
55 77
        return $prefList;
56
    }
57
}
58