Passed
Push — master ( 1dec9d...52e6bb )
by Mr
02:01
created

Query::getEndpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace RouterOS;
4
5
use RouterOS\Interfaces\QueryInterface;
6
7
/**
8
 * Class Query
9
 * @package RouterOS
10
 * @since 0.1
11
 */
12
class Query implements QueryInterface
13
{
14
    /**
15
     * Array of query attributes
16
     * @var array
17
     */
18
    private $_attributes = [];
19
20
    /**
21
     * Endpoint of query
22
     * @var string
23
     */
24
    private $_endpoint;
25
26
    /**
27
     * Query constructor.
28
     *
29
     * @param   string $endpoint Path of endpoint
30
     */
31 5
    public function __construct(string $endpoint)
32
    {
33 5
        $this->_endpoint = $endpoint;
34 5
    }
35
36
    /**
37
     * Append to array yet another attribute of query
38
     *
39
     * @param   string $word
40
     * @return  QueryInterface
41
     */
42 2
    public function add(string $word): QueryInterface
43
    {
44 2
        $this->_attributes[] = $word;
45 2
        return $this;
46
    }
47
48
    /**
49
     * Get attributes array of current query
50
     *
51
     * @return  array
52
     */
53 3
    public function getAttributes(): array
54
    {
55 3
        return $this->_attributes;
56
    }
57
58
    /**
59
     * Get endpoint of current query
60
     *
61
     * @return  string
62
     */
63 2
    public function getEndpoint(): string
64
    {
65 2
        return $this->_endpoint;
66
    }
67
68
    /**
69
     * Build body of query
70
     *
71
     * @return  array
72
     */
73 1
    public function getQuery(): array
74
    {
75 1
        $endpoint = $this->getEndpoint();
76 1
        $attributes = $this->getAttributes();
77 1
        array_unshift($attributes, $endpoint);
78
79 1
        return $attributes;
80
    }
81
}
82