OrderBy::isAsc()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
use RDS\Hydrogen\Criteria\Common\Field;
13
use RDS\Hydrogen\Query;
14
15
/**
16
 * Class OrderBy
17
 */
18
class OrderBy extends Criterion
19
{
20
    public const ASC = 'ASC';
21
    public const DESC = 'DESC';
22
23
    /**
24
     * @var bool
25
     */
26
    private $asc;
27
28
    /**
29
     * @var Field
30
     */
31
    private $field;
32
33
    /**
34
     * OrderBy constructor.
35
     * @param Query $query
36
     * @param string $field
37
     * @param bool $asc
38
     */
39 2
    public function __construct(Query $query, string $field, bool $asc = true)
40
    {
41 2
        parent::__construct($query);
42
43 2
        $this->field = $this->field($field);
44 2
        $this->asc = $asc;
45 2
    }
46
47
    /**
48
     * @return Field
49
     */
50 2
    public function getField(): Field
51
    {
52 2
        return $this->field;
53
    }
54
55
    /**
56
     * @return string
57
     */
58 2
    public function getDirection(): string
59
    {
60 2
        return $this->asc ? static::ASC : static::DESC;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function isAsc(): bool
67
    {
68
        return $this->asc;
69
    }
70
71
    /**
72
     * @return bool
73
     */
74
    public function isDesc(): bool
75
    {
76
        return ! $this->asc;
77
    }
78
}
79