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

SocialSentiment   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 25.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 52%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 19
loc 75
ccs 13
cts 25
cp 0.52
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setType() 0 6 1
A setDate() 0 8 1
A getFullEndpoint() 9 9 1
A validateParams() 0 6 2
A validateDate() 10 10 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\AlternativeData;
4
5
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
6
use Digitonic\IexCloudSdk\Exceptions\WrongData;
7
use Digitonic\IexCloudSdk\Requests\BaseRequest;
8
9
class SocialSentiment extends BaseRequest
10
{
11
    const ENDPOINT = 'stock/{symbol}/sentiment/{type}/{date}';
12
13
    /**
14
     * @var string
15
     */
16
    private $type = 'daily';
17
18
    /**
19
     * @var string
20
     */
21
    private $date;
22
23
    /**
24
     * Create constructor.
25
     *
26
     * @param  IEXCloud  $api
27
     */
28 3
    public function __construct(IEXCloud $api)
29
    {
30 3
        parent::__construct($api);
31 3
    }
32
33
    public function setType(string $type): self
34
    {
35
        $this->type = $type;
36
37
        return $this;
38
    }
39
40 1
    public function setDate(string $date): self
41
    {
42 1
        $this->validateDate($date);
43
44
        $this->date = $date;
45
46
        return $this;
47
    }
48
49
    /**
50
     * @return string
51
     */
52 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...
53
    {
54
        $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT);
55
        $endpoint = str_replace('{type}', $this->type, $endpoint);
56
        $endpoint = str_replace('{date}', $this->date, $endpoint);
57
58
        return $endpoint;
59
60
    }
61
62
    /**
63
     * @return bool|void
64
     * @throws WrongData
65
     */
66 1
    protected function validateParams(): void
67
    {
68 1
        if (empty($this->symbol)) {
69 1
            throw WrongData::invalidValuesProvided('Please provide a symbol to query!');
70
        }
71
    }
72
73 1 View Code Duplication
    private function validateDate(string $date)
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...
74
    {
75 1
        $re = '/(20\d{2})(\d{2})(\d{2})/mi';
76
77 1
        preg_match_all($re, $date, $matches, PREG_SET_ORDER, 0);
78
79 1
        if (empty($matches)) {
80 1
            throw WrongData::invalidValuesProvided('Format date to use YYYYMMDD to fetch sentiment data.');
81
        }
82
    }
83
}
84