Comparator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
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\Comparable;
13
14
abstract class Comparator
15
{
16
17
    /**
18
     * static constant for sorting order ascending
19
     */
20
    public const ORDER_ASC = "ASC";
21
22
    /**
23
     * static constant for sorting order descending
24
     */
25
    public const ORDER_DESC = "DESC";
26
27
    /**
28
     * static constant for a custom sorting order
29
     */
30
    public const ORDER_CUSTOM = "CUSTOM";
31
32
    /**
33
     * defines the order (ascending|descending) for a comparison
34
     *
35
     * @var string
36
     */
37
    protected $sortingOrder;
0 ignored issues
show
Coding Style introduced by
Protected member variable "sortingOrder" must contain a leading underscore
Loading history...
38
39
    /**
40
     * object/array which can be used to define a custom order
41
     * @var mixed
42
     */
43
    protected $customOrder;
0 ignored issues
show
Coding Style introduced by
Protected member variable "customOrder" must contain a leading underscore
Loading history...
44
45
    /**
46
     * Comparator constructor.
47
     * @param string $sortingOrder defines the order (ascending|descending) for a comparison
48
     * @param mixed $customOrder
49
     */
50 3
    public function __construct(string $sortingOrder = self::ORDER_ASC, $customOrder = null)
51
    {
52 3
        $this->sortingOrder = $sortingOrder;
53 3
        $this->customOrder = $customOrder;
54 3
    }
55
56
    /**
57
     * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first
58
     * argument is less than, equal to, or greater than the second.
59
     *
60
     * @param Comparable $a
61
     * @param Comparable $b
62
     * @return int
63
     */
64
    public abstract function compare(Comparable $a, Comparable $b): int;
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
65
}
66