Passed
Push — master ( 579875...62ad78 )
by Steven
01:35 queued 10s
created

KeyStats   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
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 58
loc 58
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getFullEndpoint() 6 6 2
A validateParams() 6 6 2
A only() 6 6 1

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\Stocks;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9 View Code Duplication
class KeyStats extends BaseRequest
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 = '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 4
    public function __construct(IEXCloud $api)
26
    {
27 4
        parent::__construct($api);
28 4
    }
29
30
    /**
31
     * If the field property is set, add it to the end of the endpoint string.
32
     *
33
     * @return string
34
     */
35 2
    protected function getFullEndpoint(): string
36
    {
37 2
        $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT);
38
39 2
        return $this->field ? "$endpoint/$this->field" : $endpoint;
40
    }
41
42
    /**
43
     * @return bool|void
44
     * @throws WrongData
45
     */
46 3
    protected function validateParams(): void
47
    {
48 3
        if (empty($this->symbol)) {
49 1
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
50
        }
51 2
    }
52
53
    /**
54
     * Setter for field property
55
     *
56
     * @param  string  $field
57
     *
58
     * @return KeyStats
59
     */
60 1
    public function only(string $field): self
61
    {
62 1
        $this->field = $field;
63
64 1
        return $this;
65
    }
66
}
67