Test Failed
Pull Request — master (#13)
by
unknown
04:04
created

Query::setKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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\BaseRequest;
8
9
class Query extends BaseRequest
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 3
    public function __construct(IEXCloud $api)
34
    {
35 3
        parent::__construct($api);
36 3
    }
37
38
    /**
39
     * @param  string  $id
40
     *
41
     * @return Query
42
     */
43 1
    public function setId(string $id): self
44
    {
45 1
        $this->id = $id;
46
47 1
        return $this;
48
    }
49
50
    /**
51
     * @param  string  $key
52
     *
53
     * @return Query
54
     */
55
    public function setKey(string $key): self
56
    {
57
        $this->key = $key;
58
59
        return $this;
60
    }
61
62
    /**
63
     * @param  string  $subKey
64
     *
65
     * @return Query
66
     */
67
    public function setSubKey(string $subKey): self
68
    {
69
        $this->subKey = $subKey;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77 View Code Duplication
    protected function getFullEndpoint(): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $endpoint = str_replace('{id}', $this->id, self::ENDPOINT);
80
        $endpoint = str_replace('{key}', $this->key, $endpoint);
81
        $endpoint = str_replace('{subKey}', $this->subKey, $endpoint);
82
83
        return $endpoint;
84
    }
85
86
    /**
87
     * @return bool|void
88
     */
89 2
    protected function validateParams()
90
    {
91 2
        if (empty($this->id)) {
92 1
            throw WrongData::invalidValuesProvided('ID required to identify a time series dataset.');
93
        }
94
95 1
        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
    }
101
}
102