Completed
Push — master ( 43966f...a8f3db )
by Pieter
03:10
created

Parameters   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 88
Duplicated Lines 11.36 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 3
dl 10
loc 88
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getConsumerKey() 0 4 1
A getNonce() 0 4 1
A getSignatureMethod() 0 4 1
A getTimestamp() 0 4 1
A getToken() 0 4 1
A getVersion() 0 4 1
A getAll() 0 4 1
A getBaseParameters() 0 11 1
A getParameters() 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 declare(strict_types=1);
2
3
namespace PeeHaa\AsyncTwitter\Oauth;
4
5
use PeeHaa\AsyncTwitter\Credentials\Application;
6
use PeeHaa\AsyncTwitter\Credentials\AccessToken;
7
use PeeHaa\AsyncTwitter\Request\Parameter;
8
use PeeHaa\AsyncTwitter\Request\Url;
9
10
class Parameters
11
{
12
    private $consumer;
13
14
    private $accessToken;
15
16
    private $nonce;
17
18
    private $timestamp;
19
20
    private $signatureMethod;
21
22
    private $version;
23
24
    private $parameters;
25
26
    private $url;
27
28 12
    public function __construct(Application $consumer, AccessToken $accessToken, Url $url, Parameter ...$parameters)
29
    {
30 12
        $this->consumer        = $consumer->getKey();
31 12
        $this->accessToken     = $accessToken->getToken();
32 12
        $this->nonce           = bin2hex(random_bytes(16));
33 12
        $this->timestamp       = (new \DateTimeImmutable())->format('U');
34 12
        $this->signatureMethod = 'HMAC-SHA1';
35 12
        $this->version         = '1.0';
36 12
        $this->parameters      = $parameters;
37 12
        $this->url             = $url;
38 12
    }
39
40 2
    public function getConsumerKey(): string
41
    {
42 2
        return $this->consumer;
43
    }
44
45 4
    public function getNonce(): string
46
    {
47 4
        return $this->nonce;
48
    }
49
50 2
    public function getSignatureMethod(): string
51
    {
52 2
        return $this->signatureMethod;
53
    }
54
55 2
    public function getTimestamp(): string
56
    {
57 2
        return $this->timestamp;
58
    }
59
60 2
    public function getToken(): string
61
    {
62 2
        return $this->accessToken;
63
    }
64
65 2
    public function getVersion(): string
66
    {
67 2
        return $this->version;
68
    }
69
70 5
    public function getAll(): array
71
    {
72 5
        return array_merge($this->getBaseParameters(), $this->getParameters());
73
    }
74
75 5
    private function getBaseParameters(): array
76
    {
77
        return [
78 5
            'oauth_consumer_key'     => $this->consumer,
79 5
            'oauth_token'            => $this->accessToken,
80 5
            'oauth_nonce'            => $this->nonce,
81 5
            'oauth_timestamp'        => $this->timestamp,
82 5
            'oauth_signature_method' => $this->signatureMethod,
83 5
            'oauth_version'          => $this->version,
84
        ];
85
    }
86
87 5 View Code Duplication
    private function getParameters(): array
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...
88
    {
89 5
        $parameters = [];
90
91 5
        foreach ($this->parameters as $parameter) {
92 5
            $parameters[$parameter->getKey()] = $parameter->getValue();
93
        }
94
95 5
        return $parameters;
96
    }
97
}
98