1 | <?php |
||
17 | 1 | class Sender extends BaseSender implements ISender |
|
18 | { |
||
19 | CONST URL = 'https://as.eurosms.com/sms/Sender'; |
||
20 | |||
21 | /** @var string */ |
||
22 | private $id; |
||
23 | |||
24 | /** @var string */ |
||
25 | private $key; |
||
26 | |||
27 | /** |
||
28 | * @param array $config |
||
29 | * @return self |
||
30 | */ |
||
31 | public function config($config) |
||
39 | |||
40 | /** |
||
41 | * @param IMessage $message |
||
42 | * @throws RM\SMSender\Exception |
||
43 | * @return bool|string ID of Message |
||
44 | */ |
||
45 | public function send(IMessage $message) |
||
46 | { |
||
47 | 1 | $this->check($message); |
|
|
|||
48 | 1 | $this->onBeforeSend($message); |
|
49 | 1 | $res = $this->getHttpClient()->request('GET', self::URL . '?' . str_replace(urlencode($message->getTo()), $message->getTo(), http_build_query([ |
|
50 | 1 | 'action' => ($this->debug ? 'validate' : 'send') . '1SMSHTTP', |
|
51 | 1 | 'i' => $this->id, |
|
52 | 1 | 's' => $this->getSignature($message), |
|
53 | 1 | 'd' => 1, |
|
54 | 1 | 'sender' => $message->getFrom(), |
|
55 | 1 | 'number' => $message->getTo(), |
|
56 | 1 | 'msg' => urlencode($message->getText()), |
|
57 | ]))); |
||
58 | 1 | $response = $res->getBody(); |
|
59 | 1 | if ($this->isSuccess($response)) { |
|
60 | 1 | $this->onSuccess($message, $response); |
|
61 | } else { |
||
62 | 1 | $e = new GatewayException($response); |
|
63 | 1 | $this->onError($message, $response, $e); |
|
64 | 1 | throw $e; |
|
65 | } |
||
66 | 1 | return ($this->debug) |
|
67 | 1 | ? TRUE |
|
68 | 1 | : substr(Strings::trim((string)$response), 3); |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param Message $message |
||
73 | * @return string |
||
74 | */ |
||
75 | public function getSignature(Message $message) |
||
79 | |||
80 | /** |
||
81 | * @param string $response |
||
82 | * @return boolean |
||
83 | */ |
||
84 | public function isSuccess($response) |
||
89 | |||
90 | /** |
||
91 | * @param string $id |
||
92 | * @param string $key |
||
93 | * @throws ConfigurationException |
||
94 | * @return bool |
||
95 | */ |
||
96 | private function checkConfig($id, $key) |
||
104 | |||
105 | /** |
||
106 | * @param Message $message |
||
107 | * @throws MissingParameterException |
||
108 | * @return bool |
||
109 | */ |
||
110 | private function check(Message $message) |
||
120 | } |
||
121 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.