Request   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 56
ccs 0
cts 26
cp 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A addData() 0 4 1
A addEncodedData() 0 4 1
A addEncryptedData() 0 4 1
A getEncrypter() 0 4 1
A getNonce() 0 4 1
A getPayload() 0 4 1
A setupPayload() 0 6 1
1
<?php
2
namespace Graceland\SafeInCloud;
3
4
use GuzzleHttp\ClientInterface;
5
6
class Request
7
{
8
    protected $encrypter;
9
10
    protected $nonce;
11
12
    protected $payload = [];
13
14
    protected $type;
15
16
    public function __construct($type, Encrypter $encrypter)
17
    {
18
        $this->encrypter = $encrypter;
19
        $this->nonce     = $this->encrypter->generateNonce();
20
        $this->type      = $type;
21
22
        $this->setupPayload();
23
    }
24
25
    public function addData($key, $value)
26
    {
27
        $this->payload[$key] = $value;
28
    }
29
30
    public function addEncodedData($key, $value)
31
    {
32
        $this->addData($key, base64_encode($value));
33
    }
34
35
    public function addEncryptedData($key, $value)
36
    {
37
        $this->addEncodedData($key, $this->encrypter->encrypt($value, $this->nonce));
38
    }
39
40
    public function getEncrypter()
41
    {
42
        return $this->encrypter;
43
    }
44
45
    public function getNonce()
46
    {
47
        return $this->nonce;
48
    }
49
50
    public function getPayload()
51
    {
52
        return $this->payload;
53
    }
54
55
    protected function setupPayload()
56
    {
57
        $this->addData('type', $this->type);
58
        $this->addEncodedData('nonce', $this->nonce);
59
        $this->addEncryptedData('verifier', base64_encode($this->nonce));
60
    }
61
}
62