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
Pull Request — master (#62)
by TJ
04:50 queued 02:00
created

Honeybadger::shouldReport()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
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.0.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 checkin(string $key) : void
92
    {
93
        $this->client->checkin($key);
94
    }
95
96
    /**
97
     * @param  int|string  $key
98
     * @param  int|string  $value
99
     * @return void
100
     */
101
    public function context($key, $value) : void
102
    {
103
        $this->context->set($key, $value);
104
    }
105
106
    /**
107
     * @return void
108
     */
109
    private function setHandlers() : void
110
    {
111
        if ($this->config['handlers']['exception']) {
112
            (new ExceptionHandler($this))->register();
113
        }
114
115
        if ($this->config['handlers']['error']) {
116
            (new ErrorHandler($this))->register();
117
        }
118
    }
119
120
    /**
121
     * @param  \Throwable  $throwable
122
     * @return bool
123
     */
124
    private function excludedException(Throwable $throwable) : bool
125
    {
126
        return $throwable instanceof ServiceException
127
            || in_array(
128
                get_class($throwable),
129
                $this->config['excluded_exceptions']
130
            );
131
    }
132
133
    /**
134
     * @param  \Throwable  $throwable
135
     * @return bool
136
     */
137
    private function shouldReport(Throwable $throwable) : bool
138
    {
139
        return ! $this->excludedException($throwable) && ! is_null($this->config['api_key']);
140
    }
141
}
142