Completed
Push — master ( 192638...f858f1 )
by Ivannis Suárez
05:02
created

Sort::custom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
 * Sort class.
15
 *
16
 * @author Karel Osorio Ramírez <[email protected]>
17
 */
18
class Sort
19
{
20
    /**
21
     * @var ComparatorInterface
22
     */
23
    protected static $comparator = null;
24
25
    /**
26
     * @return \Cubiche\Core\Comparable\ComparatorInterface
27
     */
28
    public static function comparator()
29
    {
30
        if (self::$comparator === null) {
31
            self::$comparator = new Comparator();
32
        }
33
34
        return self::$comparator;
35
    }
36
37
    /**
38
     * @param callable $selector
39
     * @param Order    $order
40
     *
41
     * @return \Cubiche\Core\Comparable\ComparatorInterface
42
     */
43
    public static function by(callable $selector, Order $order = null)
44
    {
45
        return new SelectorComparator($selector, $order === null ? Order::ASC() : $order);
46
    }
47
}
48