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

OrderBy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 45
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 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
/**
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