Passed
Push — develop ( 3a270c...23fb07 )
by Fabian
01:25
created

Request   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 11
c 1
b 0
f 0
dl 0
loc 72
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getMode() 0 3 1
A getApiVersion() 0 3 1
A getMerchantId() 0 3 1
A generateState() 0 8 1
A makeParameterArray() 0 3 1
A getPortalId() 0 3 1
A __construct() 0 3 1
A applyParameters() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cakasim\Payone\Sdk\Api\Message;
6
7
/**
8
 * The implementation of the API request interface.
9
 *
10
 * @author Fabian Böttcher <[email protected]>
11
 * @since 0.1.0
12
 */
13
class Request extends AbstractMessage implements RequestInterface
14
{
15
    /**
16
     * Constructs the request with provided parameters.
17
     *
18
     * @param array $parameters The request parameters.
19
     */
20
    public function __construct(array $parameters)
21
    {
22
        $this->parameters = $parameters;
23
    }
24
25
    /**
26
     * @inheritDoc
27
     */
28
    public function getMerchantId(): ?string
29
    {
30
        return $this->getParameter('mid');
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function getPortalId(): ?string
37
    {
38
        return $this->getParameter('portalid');
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function getApiVersion(): ?string
45
    {
46
        return $this->getParameter('api_version');
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function getMode(): ?string
53
    {
54
        return $this->getParameter('mode');
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    protected function generateState(): array
61
    {
62
        $state = parent::generateState();
63
64
        // Remove sensible API key information before serializing.
65
        unset($state['key']);
66
67
        return $state;
68
    }
69
70
    /**
71
     * @inheritDoc
72
     */
73
    public function applyParameters(array $parameters): void
74
    {
75
        // Merge request parameters with provided parameters.
76
        $this->parameters = array_merge($this->parameters, $parameters);
77
    }
78
79
    /**
80
     * @inheritDoc
81
     */
82
    public function makeParameterArray(): array
83
    {
84
        return $this->parameters;
85
    }
86
}
87