Request::getCryptUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
/**
3
 * @project Promopult Integra client library
4
 */
5
6
namespace Promopult\Integra;
7
8
/**
9
 * Class Request
10
 *
11
 * @author Dmitry Gladyshev <[email protected]>
12
 * @since 1.0
13
 */
14
final class Request implements \Promopult\Integra\RequestInterface
15
{
16
    private const PARAM_NAME = 'k';
17
    private const PARAM_VALUE_PREFIX = 'zaa';
18
19
    /**
20
     * @var string
21
     */
22
    private $method;
23
24
    /**
25
     * @var array
26
     */
27
    private $args;
28
29
    /**
30
     * @var CredentialsInterface
31
     */
32
    private $identity;
33
34
    /**
35
     * @var CryptInterface
36
     */
37
    private $crypt;
38
39
    /**
40
     * Request constructor.
41
     *
42
     * @param string $method
43
     * @param array $args
44
     * @param CredentialsInterface $identity
45
     * @param CryptInterface $crypt
46
     */
47
    public function __construct(
48
        string $method,
49
        array $args,
50
        CredentialsInterface $identity,
51
        CryptInterface $crypt
52
    ) {
53
        $this->method = $method;
54
        $this->args = $args;
55
        $this->identity = $identity;
56
        $this->crypt = $crypt;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function getCryptUrl(): string
63
    {
64
        return $this->identity->getApiHost() . '/'
65
            . $this->identity->getPartnerPath() . '/'
66
            . $this->method . '?'
67
            . self::PARAM_NAME . '=' . self::PARAM_VALUE_PREFIX
68
            . $this->identity->getHash()
69
            . urlencode($this->crypt->encrypt(json_encode($this->args), $this->identity->getCryptKey()))
70
        ;
71
    }
72
}
73