| Conditions | 5 |
| Paths | 7 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 38 | public function send(string $url, array $data): ?ResponseInterface |
||
| 39 | { |
||
| 40 | if (! $url) { |
||
| 41 | throw CouldNotSendNotification::microsoftTeamsWebhookUrlMissing(); |
||
| 42 | } |
||
| 43 | // convert associative array to numeric array in sections (since ms is otherwise not acception the body structure) |
||
| 44 | if (isset($data['sections'])) { |
||
| 45 | $data['sections'] = array_values($data['sections']); |
||
| 46 | } |
||
| 47 | try { |
||
| 48 | $response = $this->httpClient->post($url, [ |
||
| 49 | 'json' => $data, |
||
| 50 | ]); |
||
| 51 | } catch (ClientException $exception) { |
||
| 52 | throw CouldNotSendNotification::microsoftTeamsRespondedWithAnError($exception); |
||
| 53 | } catch (Exception $exception) { |
||
| 54 | throw CouldNotSendNotification::couldNotCommunicateWithMicrosoftTeams($exception); |
||
| 55 | } |
||
| 56 | |||
| 57 | return $response; |
||
| 58 | } |
||
| 59 | } |
||
| 60 |