Conditions | 3 |
Paths | 3 |
Total Lines | 45 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | public function send() |
||
14 | { |
||
15 | if (!$this->check()) { |
||
16 | return; |
||
17 | } |
||
18 | |||
19 | $data = $this->data; |
||
20 | |||
21 | $text = sprintf( |
||
22 | '[%s] %s%s[%s] *%s*%sin %s line %s%s', |
||
23 | $data['method'], |
||
24 | $data['fullUrl'], |
||
25 | "\n", |
||
26 | $data['class'], |
||
27 | $data['exception'], |
||
28 | "\n", |
||
29 | $data['file'], |
||
30 | $data['line'], |
||
31 | "\n \n" |
||
32 | ); |
||
33 | |||
34 | $attachments = [ |
||
35 | 'fallback' => $text, |
||
36 | 'color' => '#55688a', |
||
37 | 'text' => '', |
||
38 | ]; |
||
39 | $biggestNumberLength = strlen(max(array_keys($data['file_lines']))); |
||
40 | foreach ($data['file_lines'] as $num => $line) { |
||
41 | $num = str_pad($num, $biggestNumberLength, ' ', STR_PAD_LEFT); |
||
42 | // to be sure that we'll have no extra endings |
||
43 | $line = preg_replace('~[\r\n]~', '', $line); |
||
44 | // double spaces, so in slack it'll be more readable |
||
45 | $line = preg_replace('~(\s+)~', "$1$1", $line); |
||
46 | $attachments['text'] .= $num .'| '. $line ."\n"; |
||
47 | } |
||
48 | |||
49 | |||
50 | $url = 'https://slack.com/api/chat.postMessage?' |
||
51 | . 'token='. $this->config['token'] |
||
52 | . '&channel='. urlencode($this->config['channel']) |
||
53 | . '&text='. urlencode($text) |
||
54 | . '&username='. urlencode($this->config['username']) |
||
55 | . '&as_user=false&icon_url=http%3A%2F%2Fcherry-pie.co%2Fimg%2Flog-envelope.png&mrkdwn=1&pretty=1&attachments='. urlencode(json_encode([$attachments])); |
||
56 | |||
57 | @file_get_contents($url); |
||
|
|||
58 | } // end send |
||
61 |
If you suppress an error, we recommend checking for the error condition explicitly: