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

SortClause   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
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