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

Parameters::getConsumerKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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