Passed
Push — master ( a5a1f1...923478 )
by Steven
01:18 queued 11s
created

TradeBreak::getFullEndpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Digitonic\IexCloudSdk\InvestorsExchangeData\Deep;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\InvestorsExchangeData\Last;
8
use Digitonic\IexCloudSdk\Requests\BaseGet;
9
10
class TradeBreak extends BaseGet
11
{
12
    const ENDPOINT = 'deep/trade-breaks?symbols={symbols}&last={last}';
13
14
    /**
15
     * @var string
16
     */
17
    private $symbols;
18
19
    /**
20
     * @var int
21
     */
22
    private $last = 20;
23
24
    /**
25
     * Create constructor.
26
     *
27
     * @param  IEXCloud  $api
28
     */
29 4
    public function __construct(IEXCloud $api)
30
    {
31 4
        parent::__construct($api);
32 4
    }
33
34
    /**
35
     * @param  mixed  ...$symbols
36
     *
37
     * @return TradeBreak
38
     */
39 1
    public function setSymbols(...$symbols): self
40
    {
41 1
        $this->symbols = implode(',', $symbols);
42
43 1
        return $this;
44
    }
45
46
    /**
47
     * @param  int  $last
48
     *
49
     * @return TradeBreak
50
     */
51 2
    public function setLast(int $last): self
52
    {
53 2
        $this->validateLast($last);
54
55 1
        $this->last = $last;
56
57 1
        return $this;
58
    }
59
60
    /**
61
     * @return string
62
     */
63 1
    protected function getFullEndpoint(): string
64
    {
65 1
        $endpoint = str_replace('{symbols}', $this->symbols, self::ENDPOINT);
66 1
        $endpoint = str_replace('{last}', $this->last, $endpoint);
67
68 1
        return $endpoint;
69
    }
70
71
    /**
72
     * @return bool|void
73
     */
74 2
    protected function validateParams(): void
75
    {
76 2
        if (empty($this->symbols)) {
77 1
            throw WrongData::invalidValuesProvided('Please provide symbol(s) to query!');
78
        }
79 1
    }
80
81 2
    private function validateLast(int $last)
82
    {
83 2
        if ($last > 500) {
84 1
            throw WrongData::invalidValuesProvided('Last query param must be less than 500');
85
        }
86 1
    }
87
}
88