Passed
Push — master ( e38024...0fe072 )
by Steven
01:48 queued 14s
created

Quote::only()   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\Stocks;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class Quote extends BaseRequest
10
{
11
    const ENDPOINT = 'stock/{symbol}/quote';
12
13
    /**
14
     * IEX Cloud Documentation provides for the optional field to be added to
15
     * the end of the endpoint uri in order to retrieve a specific field.
16
     * This property allows that functionality to be used in this SDK.
17
     */
18
    public $field;
19
20
    /**
21
     * Create constructor.
22
     *
23
     * @param  IEXCloud  $api
24
     */
25 3
    public function __construct(IEXCloud $api)
26
    {
27 3
        parent::__construct($api);
28 3
    }
29
30
    /**
31
     * If the field property is set, add it to the end of the endpoint string.
32
     *
33
     * @return string
34
     */
35 1
    protected function getFullEndpoint(): string
36
    {
37 1
        $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT);
38
39 1
        return $this->field ? "$endpoint/$this->field" : $endpoint;
40
    }
41
42
    /**
43
     * @return bool|void
44
     * @throws WrongData
45
     */
46 2
    protected function validateParams(): void
47
    {
48 2
        if (empty($this->symbol)) {
49 1
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
50
        }
51 1
    }
52
53
    /**
54
     * Setter for field property
55
     *
56
     * @param  string  $field
57
     *
58
     * @return Quote
59
     */
60
    public function only(string $field): self
61
    {
62
        $this->field = $field;
63
64
        return $this;
65
    }
66
}
67