Passed
Push — master ( c8b982...0b6641 )
by Steven
02:24
created

News::getFullEndpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 7
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\Stocks;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class News extends BaseRequest
10
{
11
    const ENDPOINT = 'stock/{symbol}/news{last}';
12
13
    /**
14
     * @var int
15
     */
16
    private $last;
17
18
    /**
19
     * Create constructor.
20
     *
21
     * @param  IEXCloud  $api
22
     */
23 5
    public function __construct(IEXCloud $api)
24
    {
25 5
        parent::__construct($api);
26 5
    }
27
28
    /**
29
     * @param  int  $take
30
     *
31
     * @return $this
32
     * @throws WrongData
33
     */
34 3
    public function take(int $take): self
35
    {
36 3
        $this->validateLastParam($take);
37
38 1
        $this->last = $take;
39
40 1
        return $this;
41
    }
42
43
    /**
44
     * @return string
45
     */
46 1 View Code Duplication
    protected function getFullEndpoint(): string
0 ignored issues
show
Duplication introduced by
This method 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...
47
    {
48 1
        $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT);
49 1
        $endpoint = str_replace('{last}', "/last/$this->last", $endpoint);
50
51 1
        return $endpoint;
52
    }
53
54
    /**
55
     * @return bool|void
56
     * @throws WrongData
57
     */
58 2
    protected function validateParams(): void
59
    {
60 2
        if (empty($this->symbol)) {
61 1
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
62
        }
63 1
    }
64
65
    /**
66
     * @param  int  $take
67
     *
68
     * @throws WrongData
69
     */
70 3
    private function validateLastParam(int $take)
71
    {
72 3
        if ($take < 1) {
73 1
            throw WrongData::invalidValuesProvided('Must take at least one item.');
74
        }
75
76 2
        if ($take > 50) {
77 1
            throw WrongData::invalidValuesProvided('Cannot take more than 50 items in one call');
78
        }
79 1
    }
80
}
81