Passed
Push — master ( 579875...62ad78 )
by Steven
01:35 queued 10s
created

KeyStats::only()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 6
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\Stocks;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9 View Code Duplication
class KeyStats extends BaseRequest
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    const ENDPOINT = 'stock/{symbol}/stats';
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 4
    public function __construct(IEXCloud $api)
26
    {
27 4
        parent::__construct($api);
28 4
    }
29
30
    /**
31
     * If the field property is set, add it to the end of the endpoint string.
32
     *
33
     * @return string
34
     */
35 2
    protected function getFullEndpoint(): string
36
    {
37 2
        $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT);
38
39 2
        return $this->field ? "$endpoint/$this->field" : $endpoint;
40
    }
41
42
    /**
43
     * @return bool|void
44
     * @throws WrongData
45
     */
46 3
    protected function validateParams(): void
47
    {
48 3
        if (empty($this->symbol)) {
49 1
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
50
        }
51 2
    }
52
53
    /**
54
     * Setter for field property
55
     *
56
     * @param  string  $field
57
     *
58
     * @return KeyStats
59
     */
60 1
    public function only(string $field): self
61
    {
62 1
        $this->field = $field;
63
64 1
        return $this;
65
    }
66
}
67