OrderBy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 61
ccs 9
cts 13
cp 0.6923
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getField() 0 4 1
A getDirection() 0 4 2
A isAsc() 0 4 1
A isDesc() 0 4 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
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