OrderBy::setColumn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 6/3/14
5
 * Time: 12:07 AM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Sql\QueryBuilder\Syntax;
12
13
/**
14
 * Class OrderBy.
15
 */
16
class OrderBy
17
{
18
    const ASC = 'ASC';
19
    const DESC = 'DESC';
20
21
    /**
22
     * @var Column
23
     */
24
    protected $column;
25
26
    /**
27
     * @var string
28
     */
29
    protected $direction;
30
31
    /**
32
     * @var bool
33
     */
34
    protected $useAlias;
35
36
    /**
37
     * @param Column $column
38
     * @param string $direction
39
     */
40
    public function __construct(Column $column, $direction)
41
    {
42
        $this->setColumn($column);
43
        $this->setDirection($direction);
44
    }
45
46
    /**
47
     * @return Column
48
     */
49
    public function getColumn()
50
    {
51
        return $this->column;
52
    }
53
54
    /**
55
     * @param Column $column
56
     *
57
     * @return $this
58
     */
59
    public function setColumn($column)
60
    {
61
        $this->column = $column;
62
63
        return $this;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getDirection()
70
    {
71
        return $this->direction;
72
    }
73
74
    /**
75
     * @param string $direction
76
     *
77
     * @throws \InvalidArgumentException
78
     *
79
     * @return $this
80
     */
81
    public function setDirection($direction)
82
    {
83
        if (!in_array($direction, array(self::ASC, self::DESC))) {
84
            throw new \InvalidArgumentException(
85
                "Specified direction '$direction' is not allowed. Only ASC or DESC are allowed."
86
            );
87
        }
88
        $this->direction = $direction;
89
90
        return $this;
91
    }
92
}
93