Code Duplication    Length = 49-58 lines in 3 locations

src/Stocks/DelayedQuote.php 1 location

@@ 9-57 (lines=49) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class DelayedQuote extends BaseRequest
10
{
11
    const ENDPOINT = 'stock/{symbol}/delayed-quote';
12
13
    /**
14
     * @var bool
15
     */
16
    protected $oddLot = false;
17
18
    /**
19
     * Create constructor.
20
     *
21
     * @param  IEXCloud  $api
22
     */
23
    public function __construct(IEXCloud $api)
24
    {
25
        parent::__construct($api);
26
    }
27
28
    /**
29
     * If the oddLot property is set, add it to the end of the endpoint string.
30
     *
31
     * @return string
32
     */
33
    protected function getFullEndpoint(): string
34
    {
35
        $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT);
36
37
        return $this->oddLot ? "$endpoint/oddLot=$this->oddLot" : $endpoint;
38
    }
39
40
    /**
41
     * @return bool|void
42
     * @throws WrongData
43
     */
44
    protected function validateParams(): void
45
    {
46
        if (empty($this->symbol)) {
47
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
48
        }
49
    }
50
51
    public function oddLot(bool $oddLot = true): self
52
    {
53
        $this->oddLot = $oddLot;
54
55
        return $this;
56
    }
57
}
58

src/Stocks/KeyStats.php 1 location

@@ 9-66 (lines=58) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class KeyStats extends BaseRequest
10
{
11
    const ENDPOINT = 'stock/{symbol}/stats';
12
13
    /**
14
     * IEX Cloud Documentation provides for the optional field to be added to
15
     * the end of the endpoint uri in order to retrieve a specific field.
16
     * This property allows that functionality to be used in this SDK.
17
     */
18
    public $field;
19
20
    /**
21
     * Create constructor.
22
     *
23
     * @param  IEXCloud  $api
24
     */
25
    public function __construct(IEXCloud $api)
26
    {
27
        parent::__construct($api);
28
    }
29
30
    /**
31
     * If the field property is set, add it to the end of the endpoint string.
32
     *
33
     * @return string
34
     */
35
    protected function getFullEndpoint(): string
36
    {
37
        $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT);
38
39
        return $this->field ? "$endpoint/$this->field" : $endpoint;
40
    }
41
42
    /**
43
     * @return bool|void
44
     * @throws WrongData
45
     */
46
    protected function validateParams(): void
47
    {
48
        if (empty($this->symbol)) {
49
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
50
        }
51
    }
52
53
    /**
54
     * Setter for field property
55
     *
56
     * @param  string  $field
57
     *
58
     * @return KeyStats
59
     */
60
    public function only(string $field): self
61
    {
62
        $this->field = $field;
63
64
        return $this;
65
    }
66
}
67

src/Stocks/Quote.php 1 location

@@ 9-66 (lines=58) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class Quote extends BaseRequest
10
{
11
    const ENDPOINT = 'stock/{symbol}/quote';
12
13
    /**
14
     * IEX Cloud Documentation provides for the optional field to be added to
15
     * the end of the endpoint uri in order to retrieve a specific field.
16
     * This property allows that functionality to be used in this SDK.
17
     */
18
    public $field;
19
20
    /**
21
     * Create constructor.
22
     *
23
     * @param  IEXCloud  $api
24
     */
25
    public function __construct(IEXCloud $api)
26
    {
27
        parent::__construct($api);
28
    }
29
30
    /**
31
     * If the field property is set, add it to the end of the endpoint string.
32
     *
33
     * @return string
34
     */
35
    protected function getFullEndpoint(): string
36
    {
37
        $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT);
38
39
        return $this->field ? "$endpoint/$this->field" : $endpoint;
40
    }
41
42
    /**
43
     * @return bool|void
44
     * @throws WrongData
45
     */
46
    protected function validateParams(): void
47
    {
48
        if (empty($this->symbol)) {
49
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
50
        }
51
    }
52
53
    /**
54
     * Setter for field property
55
     *
56
     * @param  string  $field
57
     *
58
     * @return Quote
59
     */
60
    public function only(string $field): self
61
    {
62
        $this->field = $field;
63
64
        return $this;
65
    }
66
}
67