Passed
Push — master ( d88bb3...f13907 )
by Steven
01:04
created

Query::setSubKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Digitonic\IexCloudSdk\DataApis\TimeSeries;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseGet;
8
9
class Query extends BaseGet
10
{
11
    const ENDPOINT = 'time-series/{id}/{key}/{subKey}';
12
13
    /**
14
     * @var string
15
     */
16
    protected $id = '';
17
18
    /**
19
     * @var string
20
     */
21
    protected $key = '';
22
23
    /**
24
     * @var string
25
     */
26
    protected $subKey = '';
27
28
    /**
29
     * Create constructor.
30
     *
31
     * @param  IEXCloud  $api
32
     */
33 4
    public function __construct(IEXCloud $api)
34
    {
35 4
        parent::__construct($api);
36 4
    }
37
38
    /**
39
     * @param  string  $id
40
     *
41
     * @return Query
42
     */
43 2
    public function setId(string $id): self
44
    {
45 2
        $this->id = $id;
46
47 2
        return $this;
48
    }
49
50
    /**
51
     * @param  string  $key
52
     *
53
     * @return Query
54
     */
55 1
    public function setKey(string $key): self
56
    {
57 1
        $this->key = $key;
58
59 1
        return $this;
60
    }
61
62
    /**
63
     * @param  string  $subKey
64
     *
65
     * @return Query
66
     */
67 1
    public function setSubKey(string $subKey): self
68
    {
69 1
        $this->subKey = $subKey;
70
71 1
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77 1
    protected function getFullEndpoint(): string
78
    {
79 1
        $endpoint = str_replace('{id}', $this->id, self::ENDPOINT);
80 1
        $endpoint = str_replace('{key}', $this->key, $endpoint);
81 1
        $endpoint = str_replace('{subKey}', $this->subKey, $endpoint);
82
83 1
        return $endpoint;
84
    }
85
86
    /**
87
     * @return bool|void
88
     */
89 3
    protected function validateParams()
90
    {
91 3
        if (empty($this->id)) {
92 1
            throw WrongData::invalidValuesProvided('ID required to identify a time series dataset.');
93
        }
94
95 2
        if (empty($this->key)) {
96 1
            throw WrongData::invalidValuesProvided(
97 1
                'Key required to identify data within a dataset. A common example is a symbol such as AAPL.'
98
            );
99
        }
100 1
    }
101
}
102