Test Failed
Pull Request — master (#13)
by
unknown
02:56
created

Generic::validateParams()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Digitonic\IexCloudSdk\Requests;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
7
class Generic extends BaseRequest
8
{
9
    private $endpoint  = '';
10
    private $params    = '';
11
    protected $payload = [];
12
13
    /**
14
     * Create constructor.
15
     *
16
     * @param  IEXCloud  $api
17
     */
18
    public function __construct(IEXCloud $api)
19
    {
20
        parent::__construct($api);
21
    }
22
23
    /**
24
     * @return string
25
     */
26
    protected function getFullEndpoint(): string
27
    {
28
        return $this->endpoint . $this->getParamsForUrl();
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    protected function getParamsForUrl() {
35
        return $this->method == 'GET' ? ($this->params ? '?' . http_build_query($this->params) : '') : '';
36
    }
37
38
    /**
39
     * @return bool|void
40
     */
41
    protected function validateParams(): void
42
    {
43
        if (empty($this->endpoint)) {
44
            throw WrongData::invalidValuesProvided('Please provide endpoint!');
45
        }
46
    }
47
48
    /**
49
     * Set endpoint
50
     *
51
     * @param $endpoint
52
     * @return Generic
53
     */
54
    public function setEndpoint($endpoint) {
55
        $this->endpoint = $endpoint;
56
        return $this;
57
    }
58
59
    /**
60
     * Set params
61
     *
62
     * @param $params
63
     * @return Generic
64
     */
65
    public function setParams(array $params = []) {
66
        $this->params = $params;
0 ignored issues
show
Documentation Bug introduced by
It seems like $params of type array is incompatible with the declared type string of property $params.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
67
        return $this;
68
    }
69
70
    /**
71
     * Set payload for post request
72
     *
73
     * @param $payload
74
     * @return Generic
75
     */
76
    public function setPayload(array $payload = []) {
77
        $this->payload = $payload;
78
        return $this;
79
    }
80
}
81