Request::getPayload()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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