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

MatchedPreferenceSort   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 2
cbo 1
dl 0
loc 44
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sortAscending() 0 13 1
A sortDescending() 0 13 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