Completed
Pull Request — master (#7)
by
unknown
01:16
created

NetgsmOtpMessage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 66
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createXmlPost() 0 21 2
A getUrl() 0 4 1
A mappers() 0 8 2
1
<?php
2
3
namespace TarfinLabs\Netgsm\Sms;
4
5
use TarfinLabs\Netgsm\NetgsmErrors;
6
7
class NetgsmOtpMessage extends AbstractNetgsmMessage
8
{
9
    protected $url = 'sms/send/otp';
10
11
    protected $errorCodes = [
12
        '20'  => NetgsmErrors::MESSAGE_TOO_LONG,
13
        '30'  => NetgsmErrors::CREDENTIALS_INCORRECT,
14
        '40'  => NetgsmErrors::SENDER_INCORRECT,
15
        '50'  => NetgsmErrors::RECEIVER_INCORRECT,
16
        '60'  => NetgsmErrors::OTP_ACCOUNT_NOT_DEFINED,
17
        '70'  => NetgsmErrors::PARAMETERS_INCORRECT,
18
        '80'  => NetgsmErrors::QUERY_LIMIT_EXCEED,
19
        '100' => NetgsmErrors::SYSTEM_ERROR,
20
    ];
21
22
    protected $fields = [
23
        'msgheader',
24
        'msg',
25
        'no',
26
    ];
27
28
    /**
29
     * @return string
30
     */
31
    protected function createXmlPost(): string
32
    {
33
        $xml = '<?xml version="1.0" encoding="UTF-8"?>';
34
        $xml .= '<mainbody>';
35
        $xml .= '<header>';
36
        $xml .= '<usercode>'.$this->credentials['user_code'].'</usercode>';
37
        $xml .= '<password>'.$this->credentials['secret'].'</password>';
38
        $xml .= '<msgheader>'.$this->getHeader().'</msgheader>';
39
        $xml .= '</header>';
40
        $xml .= '<body>';
41
        $xml .= '<msg>';
42
        $xml .= '<![CDATA['.$this->message.']]>';
43
        $xml .= '</msg>';
44
        foreach ($this->recipients as $recipient) {
45
            $xml .= '<no>'.$recipient.'</no>';
46
        }
47
        $xml .= '</body>';
48
        $xml .= '</mainbody>';
49
50
        return $xml;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getUrl(): string
57
    {
58
        return $this->url;
59
    }
60
61
    /**
62
     * @return array
63
     */
64
    protected function mappers(): array
65
    {
66
        return [
67
            'msgheader' => $this->header ?? $this->defaults['header'],
68
            'msg'       => $this->message,
69
            'no'        => is_array($this->recipients) ? $this->recipients[0] : $this->recipients,
70
        ];
71
    }
72
}
73