Test Failed
Pull Request — master (#13)
by
unknown
04:04
created

News   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 9.72 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 7
loc 72
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A take() 0 8 1
A getFullEndpoint() 7 7 1
A validateParams() 0 6 2
A validateLastParam() 0 10 3

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
class News extends BaseRequest
10
{
11
    const ENDPOINT = 'stock/{symbol}/news{last}';
12
13
    /**
14
     * @var int
15
     */
16
    private $last;
17
18
    /**
19
     * Create constructor.
20
     *
21
     * @param  IEXCloud  $api
22
     */
23 4
    public function __construct(IEXCloud $api)
24
    {
25 4
        parent::__construct($api);
26 4
    }
27
28
    /**
29
     * @param  int  $take
30
     *
31
     * @return $this
32
     * @throws WrongData
33
     */
34 2
    public function take(int $take): self
35
    {
36 2
        $this->validateLastParam($take);
37
38
        $this->last = $take;
39
40
        return $this;
41
    }
42
43
    /**
44
     * @return string
45
     */
46 View Code Duplication
    protected function getFullEndpoint(): string
0 ignored issues
show
Duplication introduced by
This method 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...
47
    {
48
        $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT);
49
        $endpoint = str_replace('{last}', "/last/$this->last", $endpoint);
50
51
        return $endpoint;
52
    }
53
54
    /**
55
     * @return bool|void
56
     * @throws WrongData
57
     */
58 1
    protected function validateParams(): void
59
    {
60 1
        if (empty($this->symbol)) {
61 1
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
62
        }
63
    }
64
65
    /**
66
     * @param  int  $take
67
     *
68
     * @throws WrongData
69
     */
70 2
    private function validateLastParam(int $take)
71
    {
72 2
        if ($take < 1) {
73 1
            throw WrongData::invalidValuesProvided('Must take at least one item.');
74
        }
75
76 1
        if ($take > 50) {
77 1
            throw WrongData::invalidValuesProvided('Cannot take more than 50 items in one call');
78
        }
79
    }
80
}
81