Code Duplication    Length = 64-71 lines in 2 locations

src/DataApis/DataPoints.php 1 location

@@ 9-79 (lines=71) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseGet;
8
9
class DataPoints extends BaseGet
10
{
11
    const ENDPOINT = 'data-points/{symbol}/{key}';
12
13
    /**
14
     * @var string
15
     */
16
    protected $symbol = '';
17
18
    /**
19
     * @var string
20
     */
21
    protected $key = '';
22
23
    /**
24
     * Create constructor.
25
     *
26
     * @param  IEXCloud  $api
27
     */
28
    public function __construct(IEXCloud $api)
29
    {
30
        parent::__construct($api);
31
    }
32
33
    /**
34
     * @param  string  $symbol
35
     *
36
     * @return DataPoints
37
     */
38
    public function setSymbol(string $symbol): self
39
    {
40
        $this->symbol = $symbol;
41
42
        return $this;
43
    }
44
45
    /**
46
     * @param  string  $key
47
     *
48
     * @return DataPoints
49
     */
50
    public function setKey(string $key): self
51
    {
52
        $this->key = $key;
53
54
        return $this;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    protected function getFullEndpoint(): string
61
    {
62
        return str_replace(
63
            '{symbol}',
64
            $this->symbol,
65
            str_replace(
66
                '{key}',
67
                $this->key,
68
                self::ENDPOINT
69
            )
70
        );
71
    }
72
73
    protected function validateParams()
74
    {
75
        if (empty($this->symbol)) {
76
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
77
        }
78
    }
79
}
80

src/ForexCurrencies/ExchangeRates.php 1 location

@@ 8-71 (lines=64) @@
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Requests\BaseGet;
7
8
class ExchangeRates extends BaseGet
9
{
10
    const ENDPOINT = 'fx/rate/{from}/{to}';
11
12
    /**
13
     * @var string
14
     */
15
    private $fromCurrency = 'USD';
16
17
    /**
18
     * @var string
19
     */
20
    private $toCurrency = 'GBP';
21
22
    /**
23
     * Create constructor.
24
     *
25
     * @param  IEXCloud  $api
26
     */
27
    public function __construct(IEXCloud $api)
28
    {
29
        parent::__construct($api);
30
    }
31
32
    /**
33
     * @param  string  $fromCurrency
34
     *
35
     * @return ExchangeRates
36
     */
37
    public function setFrom(string $fromCurrency): self
38
    {
39
        $this->fromCurrency = $fromCurrency;
40
41
        return $this;
42
    }
43
44
    /**
45
     * @param  string  $toCurrency
46
     *
47
     * @return ExchangeRates
48
     */
49
    public function setTo(string $toCurrency): self
50
    {
51
        $this->toCurrency = $toCurrency;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    protected function getFullEndpoint(): string
60
    {
61
        return str_replace(
62
            '{from}',
63
            $this->fromCurrency,
64
            str_replace(
65
                '{to}',
66
                $this->toCurrency,
67
                self::ENDPOINT
68
            )
69
        );
70
    }
71
}
72