Passed
Pull Request — develop (#4)
by Vytautas
02:50
created

MobileHash::getAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace Isign\Sign;
3
4
use Isign\QueryInterface;
5
use Isign\Validator\Constraints\Code;
6
use Isign\Validator\Constraints\Phone;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
/**
10
 * Sign document using mobile ID hash.
11
 */
12
class MobileHash implements QueryInterface
13
{
14
    /** @var string user phone number */
15
    private $phone;
16
17
    /** @var string user personal code */
18
    private $code;
19
    
20
    /** @var string Hash to sign */
21
    private $hash;
22
    
23
    /** @var string Hash algorithm */
24
    private $hashAlgorithm;
25
    
26
    /** @var string Signature encryption type. */
27
    private $encryption;
28
    
29
    /** @var string Message displayed on the phone screen. Attention: UTF-8 symbols are not allowed */
30
    private $message;
31
32
    /** @var string Language for messages displayed on the phone screen */
33
    private $language;
34
35
    /**
36
     * @param string $phone
37
     * @param string $code
38
     * @param string $hash
39
     * @param string $hashAlgorithm
40
     * @param string $encryption
41
     * @param string $message
42
     * @param string $language
43
     */
44 5
    public function __construct(
45
        $phone,
46
        $code,
47
        $hash,
48
        $hashAlgorithm,
49
        $encryption,
50
        $message,
51
        $language
52
    ) {
53 5
        $this->phone = $phone;
54 5
        $this->code = $code;
55 5
        $this->hash = $hash;
56 5
        $this->hashAlgorithm = $hashAlgorithm;
57 5
        $this->encryption = $encryption;
58 5
        $this->message = $message;
59 5
        $this->language = $language;
60 5
    }
61
62
    /**
63
     * Field and values association used in query
64
     * @return array
65
     */
66 1
    public function getFields()
67
    {
68
        return [
69 1
            'phone' => $this->phone,
70 1
            'code' => $this->code,
71 1
            'hash' => $this->hash,
72 1
            'hash_algorithm' => $this->hashAlgorithm,
73 1
            'encryption' => $this->encryption,
74 1
            'message' => $this->message,
75 1
            'language' => $this->language,
76 1
        ];
77
    }
78
79
    /**
80
     * Validation constraints for request data validation
81
     * @return Assert\Collection
82
     */
83 1
    public function getValidationConstraints()
84
    {
85 1
        return new Assert\Collection([
86 1
            'phone' => new Assert\Required([
87 1
                new Assert\NotBlank(),
88 1
                new Phone(),
89 1
            ]),
90 1
            'code' => new Assert\Required([
91 1
                new Assert\NotBlank(),
92 1
                new Code()
93 1
            ]),
94 1
            'hash' => new Assert\NotBlank(),
95 1
            'hash_algorithm' => new Assert\NotBlank(),
96 1
            'encryption' => new Assert\NotBlank(),
97 1
            'message' => new Assert\NotBlank(),
98 1
            'language' => new Assert\NotBlank(),
99 1
        ]);
100
    }
101
102
    /**
103
     * Result object for this query result
104
     * @return MobileHashResult
105
     */
106 1
    public function createResult()
107
    {
108 1
        return new MobileHashResult();
109
    }
110
111
    /**
112
     * API action name, part of full API request url
113
     * @return string
114
     */
115 1
    public function getAction()
116
    {
117 1
        return 'mobile/sign/hash';
118
    }
119
120
    /**
121
     * HTTP method to use
122
     * @return string
123
     */
124 1
    public function getMethod()
125
    {
126 1
        return QueryInterface::POST;
127
    }
128
}
129