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

TradeBreak   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 78
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setSymbols() 0 6 1
A setLast() 0 8 1
A getFullEndpoint() 0 7 1
A validateParams() 0 6 2
A validateLast() 0 6 2
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