| Conditions | 4 |
| Paths | 4 |
| Total Lines | 33 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 20 | public function send(Notification $notification, array $options = []) |
||
| 21 | { |
||
| 22 | if (!isset($options['webhook'])) { |
||
| 23 | Log::error('Invalid notification configuration - slack webhook missing', [ |
||
| 24 | 'options' => $options, |
||
| 25 | ]); |
||
| 26 | return false; |
||
| 27 | } |
||
| 28 | if (false === ($curl = curl_init($options['webhook']))) { |
||
| 29 | Log::error('Unable to initialise slack webhook curl handle'); |
||
| 30 | return false; |
||
| 31 | } |
||
| 32 | $payload = json_encode([ |
||
| 33 | 'text' => $notification->getMessage(), |
||
| 34 | ]); |
||
| 35 | curl_setopt_array($curl, [ |
||
| 36 | CURLOPT_USERAGENT => 'ronanchilvers/deploy - curl ' . curl_version()['version'], |
||
| 37 | CURLOPT_FOLLOWLOCATION => false, |
||
| 38 | CURLOPT_RETURNTRANSFER => true, |
||
| 39 | CURLOPT_TIMEOUT => 5, |
||
| 40 | CURLOPT_POST => true, |
||
| 41 | CURLOPT_POSTFIELDS => ['payload' => $payload], |
||
| 42 | ]); |
||
| 43 | $result = curl_exec($curl); |
||
| 44 | $info = curl_getinfo($curl); |
||
| 45 | if (!$result) { |
||
| 46 | Log::error('Unable to send slack message to webhook', $info); |
||
| 47 | } else { |
||
| 48 | Log::debug('Sent slack message to webhook', $info); |
||
| 49 | } |
||
| 50 | curl_close($curl); |
||
| 51 | |||
| 52 | return true; |
||
| 53 | } |
||
| 55 |