Passed
Push — master ( d88bb3...f13907 )
by Steven
01:04
created

DataPoints   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 71
loc 71
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A setSymbol() 6 6 1
A setKey() 6 6 1
A getFullEndpoint() 12 12 1
A validateParams() 6 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Digitonic\IexCloudSdk\DataApis;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseGet;
8
9 View Code Duplication
class DataPoints extends BaseGet
0 ignored issues
show
Duplication introduced by
This class 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...
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 4
    public function __construct(IEXCloud $api)
29
    {
30 4
        parent::__construct($api);
31 4
    }
32
33
    /**
34
     * @param  string  $symbol
35
     *
36
     * @return DataPoints
37
     */
38 2
    public function setSymbol(string $symbol): self
39
    {
40 2
        $this->symbol = $symbol;
41
42 2
        return $this;
43
    }
44
45
    /**
46
     * @param  string  $key
47
     *
48
     * @return DataPoints
49
     */
50 1
    public function setKey(string $key): self
51
    {
52 1
        $this->key = $key;
53
54 1
        return $this;
55
    }
56
57
    /**
58
     * @return string
59
     */
60 2
    protected function getFullEndpoint(): string
61
    {
62 2
        return str_replace(
63 2
            '{symbol}',
64 2
            $this->symbol,
65 2
            str_replace(
66 2
                '{key}',
67 2
                $this->key,
68 2
                self::ENDPOINT
69
            )
70
        );
71
    }
72
73 3
    protected function validateParams()
74
    {
75 3
        if (empty($this->symbol)) {
76 1
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
77
        }
78 2
    }
79
}
80