GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#66)
by TJ
04:59
created

Honeybadger::rawNotification()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Honeybadger;
4
5
use Throwable;
6
use GuzzleHttp\Client;
7
use Honeybadger\Concerns\Newable;
8
use Honeybadger\Contracts\Reporter;
9
use Honeybadger\Support\Repository;
10
use Honeybadger\Handlers\ErrorHandler;
11
use Honeybadger\Handlers\ExceptionHandler;
12
use Honeybadger\Exceptions\ServiceException;
13
use Symfony\Component\HttpFoundation\Request as FoundationRequest;
14
15
class Honeybadger implements Reporter
16
{
17
    use Newable;
18
19
    /**
20
     * SDK Version.
21
     */
22
    const VERSION = '1.2.0';
23
24
    /**
25
     * Honeybadger API URL.
26
     */
27
    const API_URL = 'https://api.honeybadger.io/v1/';
28
29
    /**
30
     * @var \Honeybadger\HoneybadgerClient;
31
     */
32
    protected $client;
33
34
    /**
35
     * @var \Honeybadger\Config
36
     */
37
    protected $config;
38
39
    /**
40
     * @var \Honeybadger\Support\Repository
41
     */
42
    protected $context;
43
44
    /**
45
     * @param  array  $config
46
     * @param  \GuzzleHttp\Client  $client
47
     */
48
    public function __construct(array $config = [], Client $client = null)
49
    {
50
        $this->config = new Config($config);
51
52
        $this->client = new HoneybadgerClient($this->config, $client);
53
        $this->context = new Repository;
54
55
        $this->setHandlers();
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function notify(Throwable $throwable, FoundationRequest $request = null) : array
62
    {
63
        if (! $this->shouldReport($throwable)) {
64
            return [];
65
        }
66
67
        $notification = (new ExceptionNotification($this->config, $this->context))
68
            ->make($throwable, $request);
69
70
        return $this->client->notification($notification);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function customNotification(array $payload) : array
77
    {
78
        if (is_null($this->config['api_key'])) {
79
            return [];
80
        }
81
82
        $notification = (new CustomNotification($this->config, $this->context))
83
            ->make($payload);
84
85
        return $this->client->notification($notification);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function rawNotification(callable $callable) : array
92
    {
93
        if (is_null($this->config['api_key'])) {
94
            return [];
95
        }
96
97
        $notification = (new RawNotification($this->config, $this->context))
98
            ->make($callable($this->config, $this->context));
99
100
        return $this->client->notification($notification);
101
    }
102
103
    public function dynamicNotification(callable $closure)
104
    {
105
        if (is_null($this->config['api_key'])) {
106
            return [];
107
        }
108
109
        return $this->client->notification($closure($this->config, $this->context));
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function checkin(string $key) : void
116
    {
117
        $this->client->checkin($key);
118
    }
119
120
    /**
121
     * @param  int|string  $key
122
     * @param  int|string  $value
123
     * @return void
124
     */
125
    public function context($key, $value) : void
126
    {
127
        $this->context->set($key, $value);
128
    }
129
130
    /**
131
     * @return void
132
     */
133
    private function setHandlers() : void
134
    {
135
        if ($this->config['handlers']['exception']) {
136
            (new ExceptionHandler($this))->register();
137
        }
138
139
        if ($this->config['handlers']['error']) {
140
            (new ErrorHandler($this))->register();
141
        }
142
    }
143
144
    /**
145
     * @param  \Throwable  $throwable
146
     * @return bool
147
     */
148
    private function excludedException(Throwable $throwable) : bool
149
    {
150
        return $throwable instanceof ServiceException
151
            || in_array(
152
                get_class($throwable),
153
                $this->config['excluded_exceptions']
154
            );
155
    }
156
157
    /**
158
     * @param  \Throwable  $throwable
159
     * @return bool
160
     */
161
    private function shouldReport(Throwable $throwable) : bool
162
    {
163
        return ! $this->excludedException($throwable) && ! is_null($this->config['api_key']);
164
    }
165
}
166