Conditions | 6 |
Paths | 20 |
Total Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 9.3798 |
Changes | 0 |
1 | <?php |
||
31 | 1 | public function send($text = null): bool |
|
32 | { |
||
33 | 1 | if ($text) { |
|
34 | $this->setText($text); |
||
35 | } |
||
36 | try { |
||
37 | 1 | $request = $this->client->send($this->request, [ |
|
38 | 'query' => [ |
||
39 | 1 | 'apikey' => $this->username, |
|
40 | 1 | 'sender' => $this->sender ?? config('laravel-sms.sender'), |
|
41 | 1 | 'destination' => implode(',', $this->recipients), |
|
42 | 1 | 'mssg' => $this->text, |
|
43 | 1 | 'dnd' => config('laravel-sms.mebo_sms.dnd'), |
|
44 | ], |
||
45 | ]); |
||
46 | |||
47 | 1 | $response = json_decode($request->getBody()->getContents(), true); |
|
48 | |||
49 | 1 | if (isset($response['status']) && $response['status'] == 'OK') { |
|
50 | return true; |
||
51 | } |
||
52 | |||
53 | 1 | $this->response = $response['error']; |
|
54 | |||
55 | 1 | return false; |
|
56 | } catch (ClientException $e) { |
||
57 | logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
||
58 | $this->httpError = $e; |
||
59 | |||
60 | return false; |
||
61 | } catch (\Exception $e) { |
||
62 | logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
||
63 | $this->httpError = $e; |
||
64 | |||
65 | return false; |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 |