Passed
Push — master ( 2a6fdd...adce0a )
by Sebastian
01:17
created

Comparator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 52
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
compare() 0 1 ?
A __construct() 0 5 1
1
<?php
2
3
/*
4
 * Copyright (C) 2016 Sebastian Böttger <[email protected]>
5
 * You may use, distribute and modify this code under the
6
 * terms of the MIT license.
7
 *
8
 * You should have received a copy of the MIT license with
9
 * this file. If not, please visit: https://opensource.org/licenses/mit-license.php
10
 */
11
12
namespace Seboettg\Collection;
13
14
/**
15
 * Abstract class Comparator. If extending this class the compare function must be implemented. compare() is a
16
 * comparison function, which imposes a total ordering on some collection of objects. Comparators can be passed to a
17
 * sort method to allow precise control over the sort order.
18
 *
19
 * @package Seboettg\Collection
20
 *
21
 * @author Sebastian Böttger <[email protected]>
22
 */
23
abstract class Comparator
0 ignored issues
show
Coding Style introduced by
Comparator does not seem to conform to the naming convention (^Abstract|Factory$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
24
{
25
26
    /**
27
     * static constant for sorting order ascending
28
     */
29
    const ORDER_ASC = "ASC";
30
31
    /**
32
     * static constant for sorting order descending
33
     */
34
    const ORDER_DESC = "DESC";
35
36
    /**
37
     * static constant for a custom sorting order
38
     */
39
    const ORDER_CUSTOM = "CUSTOM";
40
41
    /**
42
     * defines the order (ascending|descending) for a comparison
43
     *
44
     * @var string
45
     */
46
    protected $sortingOrder;
47
48
    /**
49
     * object/array which can be used to define a custom order
50
     * @var mixed
51
     */
52
    protected $customOrder;
53
54
    /**
55
     * Comparator constructor.
56
     * @param string $sortingOrder defines the order (ascending|descending) for a comparison
57
     * @param mixed $customOrder
58
     */
59
    public function __construct($sortingOrder = self::ORDER_ASC, $customOrder = null)
60
    {
61
        $this->sortingOrder = $sortingOrder;
62
        $this->customOrder = $customOrder;
63
    }
64
65
    /**
66
     * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first
67
     * argument is less than, equal to, or greater than the second.
68
     *
69
     * @param Comparable $a
70
     * @param Comparable $b
71
     * @return int
72
     */
73
    public abstract function compare(Comparable $a, Comparable $b);
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
74
}
75