Passed
Push — master ( c1f9a4...4b0053 )
by Rimas
02:42 queued 32s
created

Prepare   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 21
dl 0
loc 83
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getValidationConstraints() 0 11 1
A getFields() 0 6 1
A getMethod() 0 3 1
A createResult() 0 3 1
A getAction() 0 3 1
A __construct() 0 8 1
1
<?php
2
namespace Dokobit\Gateway\Query\Signing;
3
4
use Dokobit\Gateway\Query\QueryInterface;
5
use Dokobit\Gateway\Result\ResultInterface;
6
use Dokobit\Gateway\Result\Signing\PrepareResult;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
/**
10
 * Prepare file for signing via API.
11
 * @see https://gateway-sandbox.dokobit.com/api/doc#_api_signing_prepare
12
 */
13
class Prepare implements QueryInterface
14
{
15
    /** @var string signing token */
16
    private $token;
17
18
    /** @var string signer id */
19
    private $signerId;
20
21
    /** @var string base64-encoded certificate */
22
    private $certificate;
23
24
    /**
25
     * @param string $token signing token
26
     * @param string $signerId signer id
27
     * @param string $certificate base64-encoded certificate
28
     */
29
    public function __construct(
30
        string $token,
31
        string $signerId,
32
        string $certificate
33
    ) {
34
        $this->token = $token;
35
        $this->signerId = $signerId;
36
        $this->certificate = $certificate;
37
    }
38
39
    /**
40
     * Field and values association used in query
41
     * @return array
42
     */
43
    public function getFields(): array
44
    {
45
        return [
46
            'token' => $this->token,
47
            'signer_id' => $this->signerId,
48
            'certificate' => $this->certificate,
49
        ];
50
    }
51
52
    /**
53
     * Validation constraints for request data validation
54
     * @return Assert\Collection
55
     */
56
    public function getValidationConstraints(): Assert\Collection
57
    {
58
        return new Assert\Collection([
59
            'token' => new Assert\Required([
60
                new Assert\NotBlank(),
61
            ]),
62
            'signer_id' => new Assert\Required([
63
                new Assert\NotBlank(),
64
            ]),
65
            'certificate' => new Assert\Optional([
66
                new Assert\NotBlank(),
67
            ]),
68
        ]);
69
    }
70
71
    /**
72
     * Result object for this query result
73
     * @return PrepareResult
74
     */
75
    public function createResult(): ResultInterface
76
    {
77
        return new PrepareResult();
78
    }
79
80
    /**
81
     * API action name, part of full API request url
82
     * @return string
83
     */
84
    public function getAction(): string
85
    {
86
        return "signing/{$this->token}/prepare";
87
    }
88
89
    /**
90
     * HTTP method to use
91
     * @return string
92
     */
93
    public function getMethod(): string
94
    {
95
        return QueryInterface::POST;
96
    }
97
}
98