Completed
Push — master ( cfe8d7...fcc746 )
by André
19:36 queued 06:48
created

SortClause::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\API\Repository\Values\URL\Query;
8
9
use InvalidArgumentException;
10
11
/**
12
 * This class is the base for SortClause classes, used to set sorting of URL queries.
13
 */
14
abstract class SortClause
15
{
16
    const SORT_ASC = 'ascending';
17
    const SORT_DESC = 'descending';
18
19
    /**
20
     * Sort direction.
21
     *
22
     * @var string
23
     */
24
    public $direction = self::SORT_ASC;
25
26
    /**
27
     * Sort target.
28
     *
29
     * @var string
30
     */
31
    public $target;
32
33
    /**
34
     * Constructs a new SortClause on $sortTarget in direction $sortDirection.
35
     *
36
     * @param string $sortTarget
37
     * @param string $sortDirection one of SortClause::SORT_ASC or SortClause::SORT_DESC
38
     *
39
     * @throws InvalidArgumentException if the given sort order isn't one of SortClause::SORT_ASC or SortClause::SORT_DESC
40
     */
41
    public function __construct($sortTarget, $sortDirection)
42
    {
43
        if ($sortDirection !== self::SORT_ASC && $sortDirection !== self::SORT_DESC) {
44
            throw new InvalidArgumentException('Sort direction must be one of SortClause::SORT_ASC or SortClause::SORT_DESC');
45
        }
46
47
        $this->direction = $sortDirection;
48
        $this->target = $sortTarget;
49
    }
50
}
51