SlackDriver::send()   B
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 38
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 38
rs 8.8571
cc 2
eloc 27
nc 1
nop 1
1
<?php
2
3
namespace Adriandmitroca\LaravelExceptionMonitor\Drivers;
4
5
use Carbon\Carbon;
6
use Maknz\Slack\Attachment;
7
use Maknz\Slack\AttachmentField;
8
use Maknz\Slack\Client as Slack;
9
10
class SlackDriver implements DriverInterface
11
{
12
13
    protected $slack;
14
15
16
    /**
17
     * SlackDriver constructor.
18
     *
19
     * @param Slack $slack
20
     */
21
    public function __construct(Slack $slack)
22
    {
23
        $this->slack = $slack;
24
    }
25
26
27
    public function send(\Exception $exception)
28
    {
29
        $config     = config('exception-monitor.slack');
30
        $message    = 'Exception has been thrown on `' . config('app.url') . '`';
31
        $attachment = new Attachment([
32
            'color'  => 'danger',
33
            'fields' => [
34
                new AttachmentField([
35
                    'title' => 'Message',
36
                    'value' => $exception->getMessage(),
37
                    'short' => true
38
                ]),
39
                new AttachmentField([
40
                    'title' => 'File',
41
                    'value' => $exception->getFile() . ':' . $exception->getLine(),
42
                    'short' => true
43
                ]),
44
45
                new AttachmentField([
46
                    'title' => 'Request',
47
                    'value' => app('request')->getRequestUri(),
48
                    'short' => true
49
                ]),
50
                new AttachmentField([
51
                    'title' => 'Timestamp',
52
                    'value' => Carbon::now()->toDateTimeString(),
53
                    'short' => true
54
                ]),
55
                new AttachmentField([
56
                    'title' => 'User',
57
                    'value' => auth()->check() ? auth()->user()->id : 'Not logged in',
0 ignored issues
show
Bug introduced by
The method check() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
                    'short' => true
59
                ])
60
            ]
61
        ]);
62
63
        $this->slack->to($config['channel'])->from($config['username'])->attach($attachment)->withIcon($config['icon'])->send($message);
64
    }
65
}