ReverseComparator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compare() 0 4 1
A reverse() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Comparable;
12
13
/**
14
 * Reverse Comparator class.
15
 *
16
 * @author Ivannis Suárez Jerez <[email protected]>
17
 * @author Karel Osorio Ramírez <[email protected]>
18
 */
19
class ReverseComparator extends Comparator
20
{
21
    /**
22
     * @var ComparatorInterface
23
     */
24
    protected $comparator;
25
26
    /**
27
     * @param callable $comparator
28
     */
29
    public function __construct(callable $comparator)
30
    {
31
        $this->comparator = self::from($comparator);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function compare($a, $b)
38
    {
39
        return -1 * $this->reverse()->compare($a, $b);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function reverse()
46
    {
47
        return $this->comparator;
48
    }
49
}
50