OrderBy::getDirection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\OrderBy;
5
6
use Level23\Druid\Types\SortingOrder;
7
use Level23\Druid\Types\OrderByDirection;
8
9
class OrderBy implements OrderByInterface
10
{
11
    protected string $dimension;
12
13
    protected OrderByDirection $direction;
14
15
    protected SortingOrder $dimensionOrder;
16
17
    /**
18
     * OrderBy constructor.
19
     *
20
     * @param string                  $dimension
21
     * @param string|OrderByDirection $direction
22
     * @param string|SortingOrder     $dimensionOrder
23
     */
24 25
    public function __construct(
25
        string $dimension,
26
        string|OrderByDirection $direction = OrderByDirection::ASC,
27
        string|SortingOrder $dimensionOrder = SortingOrder::LEXICOGRAPHIC
28
    ) {
29 25
        $this->dimension      = $dimension;
30 25
        $this->direction      = is_string($direction) ? OrderByDirection::make($direction) : $direction;
31 24
        $this->dimensionOrder = is_string($dimensionOrder) ? SortingOrder::from($dimensionOrder) : $dimensionOrder;
32
    }
33
34
    /**
35
     * Return the order by in array format so that it can be used in a druid query.
36
     *
37
     * @return array<string,string>
38
     */
39 12
    public function toArray(): array
40
    {
41 12
        return [
42 12
            'dimension'      => $this->dimension,
43 12
            'direction'      => $this->direction->value,
44 12
            'dimensionOrder' => $this->dimensionOrder->value,
45 12
        ];
46
    }
47
48
    /**
49
     * The dimension where we should order on.
50
     *
51
     * @return string
52
     */
53 8
    public function getDimension(): string
54
    {
55 8
        return $this->dimension;
56
    }
57
58
    /**
59
     * Return the direction of the order by
60
     *
61
     * @return OrderByDirection
62
     */
63 8
    public function getDirection(): OrderByDirection
64
    {
65 8
        return $this->direction;
66
    }
67
}
68