Conditions | 4 |
Paths | 7 |
Total Lines | 28 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 2 |
CRAP Score | 14.993 |
Changes | 0 |
1 | <?php |
||
47 | 1 | public function send($params) |
|
48 | { |
||
49 | $base = [ |
||
50 | 'charset' => 'utf-8', |
||
51 | 'login' => $this->login, |
||
52 | 'psw' => $this->secret, |
||
53 | 'sender' => $this->sender, |
||
54 | 'fmt' => self::FORMAT_JSON, |
||
55 | ]; |
||
56 | |||
57 | $params = array_merge($params, $base); |
||
58 | |||
59 | try { |
||
60 | $response = $this->httpClient->post($this->apiUrl, ['form_params' => $params]); |
||
61 | |||
62 | $response = json_decode((string) $response->getBody(), true); |
||
63 | |||
64 | if (isset($response['error'])) { |
||
65 | 1 | throw new DomainException($response['error'], $response['error_code']); |
|
66 | } |
||
67 | |||
68 | return $response; |
||
69 | } catch (DomainException $exception) { |
||
70 | throw CouldNotSendNotification::smscRespondedWithAnError($exception); |
||
71 | } catch (\Exception $exception) { |
||
72 | throw CouldNotSendNotification::couldNotCommunicateWithSmsc($exception); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 |