@@ -30,12 +30,8 @@ final class LightSmsTransport extends AbstractTransport
30
30
private $ login ;
31
31
private $ password ;
32
32
private $ phone ;
33
- /**
34
- * @var MessageInterface
35
- */
36
- private $ message ;
37
33
38
- private $ errorCodes = [
34
+ private const ERROR_CODES = [
39
35
'000 ' => 'Service unavailable ' ,
40
36
'1 ' => 'Signature not specified ' ,
41
37
'2 ' => 'Login not specified ' ,
@@ -103,9 +99,7 @@ protected function doSend(MessageInterface $message): SentMessage
103
99
throw new UnsupportedMessageTypeException (__CLASS__ , SmsMessage::class, $ message );
104
100
}
105
101
106
- $ this ->message = $ message ;
107
-
108
- $ signature = $ this ->generateSignature ();
102
+ $ signature = $ this ->generateSignature ($ message );
109
103
110
104
$ endpoint = sprintf (
111
105
'https://%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s ' ,
@@ -123,12 +117,12 @@ protected function doSend(MessageInterface $message): SentMessage
123
117
$ content = $ response ->toArray (false );
124
118
125
119
if (isset ($ content ['error ' ])) {
126
- throw new TransportException ('Unable to send the SMS: ' .$ this -> errorCodes [$ content ['error ' ]], $ response );
120
+ throw new TransportException ('Unable to send the SMS: ' .self :: ERROR_CODES [$ content ['error ' ]], $ response );
127
121
}
128
122
129
123
$ phone = preg_replace ("/[^\d]/ " , '' , $ message ->getPhone ());
130
124
if (32 == $ content [$ phone ]['error ' ]) {
131
- throw new TransportException ('Unable to send the SMS: ' .$ this -> errorCodes [$ content ['error ' ]], $ response );
125
+ throw new TransportException ('Unable to send the SMS: ' .self :: ERROR_CODES [$ content ['error ' ]], $ response );
132
126
}
133
127
134
128
if (0 == $ content [$ phone ]['error ' ]) {
@@ -139,14 +133,14 @@ protected function doSend(MessageInterface $message): SentMessage
139
133
return $ sentMessage ;
140
134
}
141
135
142
- private function generateSignature (): string
136
+ private function generateSignature (SmsMessage $ message ): string
143
137
{
144
138
$ params = [
145
139
'timestamp ' => time (),
146
140
'login ' => $ this ->login ,
147
- 'phone ' => str_replace ('+ ' , '' , $ this -> message ->getPhone ()),
141
+ 'phone ' => str_replace ('+ ' , '' , $ message ->getPhone ()),
148
142
'sender ' => $ this ->phone ,
149
- 'text ' => $ this -> message ->getSubject (),
143
+ 'text ' => $ message ->getSubject (),
150
144
];
151
145
152
146
ksort ($ params );
0 commit comments