Passed
Push — master ( ad1515...9a224a )
by Sebastian
01:48
created

Comparator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (C) 2016 Sebastian Böttger <[email protected]>
4
 * You may use, distribute and modify this code under the
5
 * terms of the MIT license.
6
 *
7
 * You should have received a copy of the MIT license with
8
 * this file. If not, please visit: https://opensource.org/licenses/mit-license.php
9
 */
10
11
namespace Seboettg\Collection\Comparable;
12
13
/**
14
 * Abstract class Comparator. When extending this class the compare function must be implemented. compare() is a
15
 * comparison function, which imposes a total ordering on some collection of objects. Comparators can be passed to a
16
 * sort method to allow precise control over the sort order.
17
 *
18
 * @package Seboettg\Collection
19
 *
20
 * @author Sebastian Böttger <[email protected]>
21
 */
22
abstract class Comparator
23
{
24
25
    /**
26
     * static constant for sorting order ascending
27
     */
28
    const ORDER_ASC = "ASC";
29
30
    /**
31
     * static constant for sorting order descending
32
     */
33
    const ORDER_DESC = "DESC";
34
35
    /**
36
     * static constant for a custom sorting order
37
     */
38
    const ORDER_CUSTOM = "CUSTOM";
39
40
    /**
41
     * defines the order (ascending|descending) for a comparison
42
     *
43
     * @var string
44
     */
45
    protected $sortingOrder;
0 ignored issues
show
Coding Style introduced by
Protected member variable "sortingOrder" must contain a leading underscore
Loading history...
46
47
    /**
48
     * object/array which can be used to define a custom order
49
     * @var mixed
50
     */
51
    protected $customOrder;
0 ignored issues
show
Coding Style introduced by
Protected member variable "customOrder" must contain a leading underscore
Loading history...
52
53
    /**
54
     * Comparator constructor.
55
     * @param string $sortingOrder defines the order (ascending|descending) for a comparison
56
     * @param mixed $customOrder
57
     */
58
    public function __construct($sortingOrder = self::ORDER_ASC, $customOrder = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$sortingOrder" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$sortingOrder"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$customOrder" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$customOrder"; expected 0 but found 1
Loading history...
59
    {
60
        $this->sortingOrder = $sortingOrder;
61
        $this->customOrder = $customOrder;
62
    }
63
64
    /**
65
     * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first
66
     * argument is less than, equal to, or greater than the second.
67
     *
68
     * @param Comparable $a
69
     * @param Comparable $b
70
     * @return int
71
     */
72
    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...
73
}
74