| Conditions | 7 |
| Paths | 25 |
| Total Lines | 30 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 7.3229 |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 27 | 7 | public function send($notifiable, InterfaxNotificationContract $notification) |
|
| 28 | { |
||
| 29 | 7 | if (! $faxNumber = $notifiable->routeNotificationFor('interfax')) { |
|
| 30 | 1 | return; |
|
| 31 | } |
||
| 32 | |||
| 33 | 6 | $message = $notification->toInterfax($notifiable); |
|
| 34 | |||
| 35 | try { |
||
| 36 | 6 | $this->fax = $this->client->deliver([ |
|
| 37 | 'faxNumber' => $faxNumber, |
||
| 38 | 6 | 'files' => $message->makeFiles(), |
|
| 39 | ]); |
||
| 40 | |||
| 41 | 6 | if ($message->shouldCheckStatus()) { |
|
| 42 | 2 | $message->sleep(); |
|
| 43 | |||
| 44 | 2 | while ($this->fax->refresh()->status < 0) { |
|
| 45 | 1 | $message->sleep(); |
|
| 46 | } |
||
| 47 | |||
| 48 | 2 | if ($this->fax->refresh()->status > 0) { |
|
| 49 | 6 | throw CouldNotSendNotification::serviceRespondedWithAnError($message, $this->fax->attributes()); |
|
| 50 | } |
||
| 51 | } |
||
| 52 | 1 | } catch (\Interfax\Exception\RequestException $e) { |
|
| 53 | $exceptionMessage = $e->getMessage().': '.($e->getWrappedException())->getMessage(); |
||
| 54 | $attributes = $this->fax ? $this->fax->attributes() : ['status' => $e->getStatusCode()]; |
||
| 55 | |||
| 56 | throw CouldNotSendNotification::serviceRespondedWithAnError($message, $attributes, $exceptionMessage); |
||
| 57 | } |
||
| 60 |