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.
Passed
Push — master ( de8a52...8b20ab )
by TJ
01:55
created

Honeybadger::setComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
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.6.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 $additionalParams = []) : array
62
    {
63
        if (! $this->shouldReport($throwable)) {
64
            return [];
65
        }
66
67
        $notification = (new ExceptionNotification($this->config, $this->context))
68
            ->make($throwable, $request, $additionalParams);
69
70
        return $this->client->notification($notification);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function customNotification(array $payload) : array
77
    {
78
        if (empty($this->config['api_key']) || ! $this->config['report_data']) {
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 (empty($this->config['api_key']) || ! $this->config['report_data']) {
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
    /**
104
     * {@inheritdoc}
105
     */
106
    public function checkin(string $key) : void
107
    {
108
        $this->client->checkin($key);
109
    }
110
111
    /**
112
     * @param  int|string  $key
113
     * @param  int|string  $value
114
     * @return void
115
     */
116
    public function context($key, $value) : void
117
    {
118
        $this->context->set($key, $value);
119
    }
120
121
    /**
122
     * @return void
123
     */
124
    public function resetContext() : void
125
    {
126
        $this->context = new Repository;
127
    }
128
129
    /**
130
     * @return \Honeybadger\Support\Repository
131
     */
132
    public function getContext() : Repository
133
    {
134
        return $this->context;
135
    }
136
137
    /**
138
     * @return void
139
     */
140
    private function setHandlers() : void
141
    {
142
        if ($this->config['handlers']['exception']) {
143
            (new ExceptionHandler($this))->register();
144
        }
145
146
        if ($this->config['handlers']['error']) {
147
            (new ErrorHandler($this))->register();
148
        }
149
    }
150
151
    /**
152
     * @param  \Throwable  $throwable
153
     * @return bool
154
     */
155
    private function excludedException(Throwable $throwable) : bool
156
    {
157
        return $throwable instanceof ServiceException
158
            || in_array(
159
                get_class($throwable),
160
                $this->config['excluded_exceptions']
161
            );
162
    }
163
164
    /**
165
     * @param  \Throwable  $throwable
166
     * @return bool
167
     */
168
    private function shouldReport(Throwable $throwable) : bool
169
    {
170
        return ! $this->excludedException($throwable)
171
            && ! empty($this->config['api_key'])
172
            && $this->config['report_data'];
173
    }
174
175
    /**
176
     * @param string $component
177
     * @return self
178
     */
179
    public function setComponent(string $component) : self
180
    {
181
        $this->context('honeybadger_component', $component);
182
183
        return $this;
184
    }
185
186
    /**
187
     * @param string $action
188
     * @return self
189
     */
190
    public function setAction(string $action) : self
191
    {
192
        $this->context('honeybadger_action', $action);
193
194
        return $this;
195
    }
196
}
197