Code Duplication    Length = 46-64 lines in 11 locations

src/DataApis/DataPoints.php 1 location

@@ 9-62 (lines=54) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class DataPoints extends BaseRequest
10
{
11
    const ENDPOINT = 'data-points/{symbol}/{key}';
12
13
    /**
14
     * @var string
15
     */
16
    protected $key = '';
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
     * @param  string  $key
30
     *
31
     * @return DataPoints
32
     */
33
    public function setKey(string $key): self
34
    {
35
        $this->key = $key;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    protected function getFullEndpoint(): string
44
    {
45
        return str_replace(
46
            '{symbol}',
47
            $this->symbol,
48
            str_replace(
49
                '{key}',
50
                $this->key,
51
                self::ENDPOINT
52
            )
53
        );
54
    }
55
56
    protected function validateParams()
57
    {
58
        if (empty($this->symbol)) {
59
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
60
        }
61
    }
62
}
63

src/ForexCurrencies/ExchangeRates.php 1 location

@@ 8-71 (lines=64) @@
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Requests\BaseRequest;
7
8
class ExchangeRates extends BaseRequest
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

src/InvestorsExchangeData/Deep/OfficialPrice.php 1 location

@@ 9-57 (lines=49) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class OfficialPrice extends BaseRequest
10
{
11
    const ENDPOINT = 'deep/official-price?symbols={symbols}';
12
13
    /**
14
     * @var string
15
     */
16
    private $symbols;
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
     * @param  mixed  ...$symbols
30
     *
31
     * @return OfficialPrice
32
     */
33
    public function setSymbols(...$symbols): self
34
    {
35
        $this->symbols = implode(',', $symbols);
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    protected function getFullEndpoint(): string
44
    {
45
        return str_replace('{symbols}', $this->symbols, self::ENDPOINT);
46
    }
47
48
    /**
49
     * @return bool|void
50
     */
51
    protected function validateParams(): void
52
    {
53
        if (empty($this->symbols)) {
54
            throw WrongData::invalidValuesProvided('Please provide symbol(s) to query!');
55
        }
56
    }
57
}
58

src/InvestorsExchangeData/Deep/OpHaltStatus.php 1 location

@@ 9-57 (lines=49) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class OpHaltStatus extends BaseRequest
10
{
11
    const ENDPOINT = 'deep/op-halt-status?symbols={symbols}';
12
13
    /**
14
     * @var string
15
     */
16
    private $symbols;
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
     * @param  mixed  ...$symbols
30
     *
31
     * @return OpHaltStatus
32
     */
33
    public function setSymbols(...$symbols): self
34
    {
35
        $this->symbols = implode(',', $symbols);
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    protected function getFullEndpoint(): string
44
    {
45
        return str_replace('{symbols}', $this->symbols, self::ENDPOINT);
46
    }
47
48
    /**
49
     * @return bool|void
50
     */
51
    protected function validateParams(): void
52
    {
53
        if (empty($this->symbols)) {
54
            throw WrongData::invalidValuesProvided('Please provide symbol(s) to query!');
55
        }
56
    }
57
}
58

src/InvestorsExchangeData/Deep/SsrStatus.php 1 location

@@ 9-57 (lines=49) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class SsrStatus extends BaseRequest
10
{
11
    const ENDPOINT = 'deep/ssr-status?symbols={symbols}';
12
13
    /**
14
     * @var string
15
     */
16
    private $symbols;
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
     * @param  mixed  ...$symbols
30
     *
31
     * @return SsrStatus
32
     */
33
    public function setSymbols(...$symbols): self
34
    {
35
        $this->symbols = implode(',', $symbols);
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    protected function getFullEndpoint(): string
44
    {
45
        return str_replace('{symbols}', $this->symbols, self::ENDPOINT);
46
    }
47
48
    /**
49
     * @return bool|void
50
     */
51
    protected function validateParams(): void
52
    {
53
        if (empty($this->symbols)) {
54
            throw WrongData::invalidValuesProvided('Please provide symbol(s) to query!');
55
        }
56
    }
57
}
58

src/InvestorsExchangeData/Deep/Trades.php 1 location

@@ 10-57 (lines=48) @@
7
use Digitonic\IexCloudSdk\InvestorsExchangeData\Last;
8
use Digitonic\IexCloudSdk\Requests\BaseRequest;
9
10
class Trades extends BaseRequest
11
{
12
    const ENDPOINT = 'deep/trades?symbols={symbols}';
13
14
    /**
15
     * @var string
16
     */
17
    private $symbols;
18
19
    /**
20
     * Create constructor.
21
     *
22
     * @param  IEXCloud  $api
23
     */
24
    public function __construct(IEXCloud $api)
25
    {
26
        parent::__construct($api);
27
    }
28
29
    /**
30
     * @param  mixed  ...$symbols
31
     *
32
     * @return Trades
33
     */
34
    public function setSymbols(...$symbols): self
35
    {
36
        $this->symbols = implode(',', $symbols);
37
38
        return $this;
39
    }
40
    /**
41
     * @return string
42
     */
43
    protected function getFullEndpoint(): string
44
    {
45
        return str_replace('{symbols}', $this->symbols, self::ENDPOINT);
46
    }
47
48
    /**
49
     * @return bool|void
50
     */
51
    protected function validateParams(): void
52
    {
53
        if (empty($this->symbols)) {
54
            throw WrongData::invalidValuesProvided('Please provide symbol(s) to query!');
55
        }
56
    }
57
}
58

src/InvestorsExchangeData/Deep/TradingStatus.php 1 location

@@ 9-57 (lines=49) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class TradingStatus extends BaseRequest
10
{
11
    const ENDPOINT = 'deep/trading-status?symbols={symbols}';
12
13
    /**
14
     * @var string
15
     */
16
    private $symbols;
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
     * @param  mixed  ...$symbols
30
     *
31
     * @return TradingStatus
32
     */
33
    public function setSymbols(...$symbols): self
34
    {
35
        $this->symbols = implode(',', $symbols);
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    protected function getFullEndpoint(): string
44
    {
45
        return str_replace('{symbols}', $this->symbols, self::ENDPOINT);
46
    }
47
48
    /**
49
     * @return bool|void
50
     */
51
    protected function validateParams(): void
52
    {
53
        if (empty($this->symbols)) {
54
            throw WrongData::invalidValuesProvided('Please provide symbol(s) to query!');
55
        }
56
    }
57
}
58

src/InvestorsExchangeData/Last.php 1 location

@@ 9-54 (lines=46) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class Last extends BaseRequest
10
{
11
    const ENDPOINT = 'tops/last?symbols={symbols}';
12
13
    protected $symbols;
14
15
    /**
16
     * Create constructor.
17
     *
18
     * @param  IEXCloud  $api
19
     */
20
    public function __construct(IEXCloud $api)
21
    {
22
        parent::__construct($api);
23
    }
24
25
    /**
26
     * @param  mixed  ...$symbols
27
     *
28
     * @return Last
29
     */
30
    public function setSymbols(...$symbols): self
31
    {
32
        $this->symbols = implode(',', $symbols);
33
34
        return $this;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    protected function getFullEndpoint(): string
41
    {
42
        return str_replace('{symbols}', $this->symbols, self::ENDPOINT);
43
    }
44
45
    /**
46
     * @return bool|void
47
     */
48
    protected function validateParams(): void
49
    {
50
        if (empty($this->symbols)) {
51
            throw WrongData::invalidValuesProvided('Please provide symbol(s) to query!');
52
        }
53
    }
54
}
55

src/InvestorsExchangeData/Tops.php 1 location

@@ 9-54 (lines=46) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class Tops extends BaseRequest
10
{
11
    const ENDPOINT = 'tops?symbols={symbols}';
12
13
    protected $symbols;
14
15
    /**
16
     * Create constructor.
17
     *
18
     * @param  IEXCloud  $api
19
     */
20
    public function __construct(IEXCloud $api)
21
    {
22
        parent::__construct($api);
23
    }
24
25
    /**
26
     * @param  mixed  ...$symbols
27
     *
28
     * @return Tops
29
     */
30
    public function setSymbols(...$symbols): self
31
    {
32
        $this->symbols = implode(',', $symbols);
33
34
        return $this;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    protected function getFullEndpoint(): string
41
    {
42
        return str_replace('{symbols}', $this->symbols, self::ENDPOINT);
43
    }
44
45
    /**
46
     * @return bool|void
47
     */
48
    protected function validateParams(): void
49
    {
50
        if (empty($this->symbols)) {
51
            throw WrongData::invalidValuesProvided('Please provide symbol(s) to query!');
52
        }
53
    }
54
}
55

src/ReferenceData/ExchangeSymbols.php 1 location

@@ 9-59 (lines=51) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class ExchangeSymbols extends BaseRequest
10
{
11
    const ENDPOINT = 'ref-data/exchange/{exchange}/symbols';
12
13
    /**
14
     * @var string
15
     */
16
    private $exchange;
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
     * @param  string  $exchange
30
     *
31
     * @return ExchangeSymbols
32
     */
33
    public function setExchange(string $exchange): self
34
    {
35
        $this->exchange = $exchange;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    protected function getFullEndpoint(): string
44
    {
45
        return str_replace('{exchange}', $this->exchange, self::ENDPOINT);
46
    }
47
48
    /**
49
     * @return bool|void
50
     */
51
    protected function validateParams(): void
52
    {
53
        if (empty($this->exchange)) {
54
            throw WrongData::invalidValuesProvided(
55
                'Required case insensitive string of Exchange using IEX Supported Exchanges list'
56
            );
57
        }
58
    }
59
}
60

src/ReferenceData/RegionSymbols.php 1 location

@@ 9-59 (lines=51) @@
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class RegionSymbols extends BaseRequest
10
{
11
    const ENDPOINT = 'ref-data/region/{region}/symbols';
12
13
    /**
14
     * @var string
15
     */
16
    private $region;
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
     * @param  string  $region
30
     *
31
     * @return RegionSymbols
32
     */
33
    public function setRegion(string $region): self
34
    {
35
        $this->region = $region;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    protected function getFullEndpoint(): string
44
    {
45
        return str_replace('{region}', $this->region, self::ENDPOINT);
46
    }
47
48
    /**
49
     * @return bool|void
50
     */
51
    protected function validateParams(): void
52
    {
53
        if (empty($this->region)) {
54
            throw WrongData::invalidValuesProvided(
55
                'Region required using 2 letter case insensitive string of country codes using ISO 3166-1 alpha-2'
56
            );
57
        }
58
    }
59
}
60