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

SocialSentiment::validateDate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 5
cts 6
cp 0.8333
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0185
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