Passed
Push — master ( f13907...f1392d )
by Steven
56s queued 12s
created

BaseGet::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
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\Requests;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use GuzzleHttp\Psr7\Request;
7
use Illuminate\Support\Collection;
8
9
class BaseGet
10
{
11
    const ENDPOINT = '';
12
13
    protected $method = 'GET';
14
15
    protected $api;
16
17
    /**
18
     * @var string
19
     */
20
    protected $symbol = '';
21
22
    /**
23
     * Create constructor.
24
     *
25
     * @param  IEXCloud  $api
26
     */
27 44
    public function __construct(IEXCloud $api)
28
    {
29 44
        $this->api = $api;
30 44
    }
31
32
    /**
33
     * @param  string  $symbol
34
     *
35
     * @return BaseGet
36
     */
37 8
    public function setSymbol(string $symbol): self
38
    {
39 8
        $this->symbol = $symbol;
40
41 8
        return $this;
42
    }
43
44
    /**
45
     * @return Collection
46
     */
47 29
    public function send(): Collection
48
    {
49 29
        $this->validateParams();
50
51 18
        $request = new Request($this->method, $this->getFullEndpoint());
52
53 18
        $response = $this->api->send($request);
54
55 18
        return collect(json_decode($response->getBody()->getContents()));
56
    }
57
58
    /**
59
     * @return string
60
     */
61 6
    protected function getFullEndpoint(): string
62
    {
63 6
        return self::ENDPOINT;
64
    }
65
66
    /**
67
     * @return bool
68
     */
69 7
    protected function validateParams()
70
    {
71 7
        return true;
72
    }
73
}
74