Completed
Push — master ( 69b436...e84470 )
by Kirill
14:54 queued 05:27
created

OrderBy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * This file is part of Hydrogen package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace RDS\Hydrogen\Criteria;
11
12
/**
13
 * Class OrderBy
14
 */
15
class OrderBy extends Criterion
16
{
17
    public const ASC = 'ASC';
18
    public const DESC = 'DESC';
19
20
    /**
21
     * @var bool
22
     */
23
    private $asc;
24
25
    /**
26
     * OrderBy constructor.
27
     * @param string $field
28
     * @param bool $asc
29
     */
30 2
    public function __construct(string $field, bool $asc = true)
31
    {
32 2
        parent::__construct($field);
33 2
        $this->asc = $asc;
34 2
    }
35
36
    /**
37
     * @return string
38
     */
39 2
    public function getDirection(): string
40
    {
41 2
        return $this->asc ? static::ASC : static::DESC;
42
    }
43
44
    /**
45
     * @return bool
46
     */
47
    public function isAsc(): bool
48
    {
49
        return $this->asc;
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function isDesc(): bool
56
    {
57
        return ! $this->asc;
58
    }
59
}
60