SortNode::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Xiag\Rql\Parser\Node;
3
4
use Xiag\Rql\Parser\AbstractNode;
5
6
/**
7
 * @codeCoverageIgnore
8
 */
9
class SortNode extends AbstractNode
10
{
11
    const SORT_ASC = 1;
12
    const SORT_DESC = -1;
13
14
    /**
15
     * @var array
16
     */
17
    protected $fields;
18
19
    /**
20
     * @param array $fields
21
     */
22
    public function __construct(array $fields = [])
23
    {
24
        $this->fields = $fields;
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function getNodeName()
31
    {
32
        return 'sort';
33
    }
34
35
    /**
36
     * @param string $field
37
     * @param int $direction
38
     * @return void
39
     */
40
    public function addField($field, $direction = self::SORT_ASC)
41
    {
42
        $this->fields[$field] = $direction;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getFields()
49
    {
50
        return $this->fields;
51
    }
52
}
53