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 (#57)
by TJ
02:43
created

ExceptionNotification::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 22
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Honeybadger;
4
5
use Throwable;
6
use Honeybadger\Support\Repository;
7
use Symfony\Component\HttpFoundation\Request as FoundationRequest;
8
9
class ExceptionNotification
10
{
11
    /**
12
     * @var \Honeybadger\Config
13
     */
14
    protected $config;
15
16
    /**
17
     * @var \Honeybadger\Support\Repository
18
     */
19
    protected $context;
20
21
    /**
22
     * @var \Throwable
23
     */
24
    protected $throwable;
25
26
    /**
27
     * @var \Honeybadger\BacktraceFactory
28
     */
29
    protected $backtrace;
30
31
    /**
32
     * @var \Honeybadger\Request
33
     */
34
    protected $request;
35
36
    /**
37
     * @var \Honeybadger\Environment
38
     */
39
    protected $environment;
40
41
    /**
42
     * @param  \Honeybadger\Config  $config
43
     * @param  \Honeybadger\Support\Repository  $context
44
     */
45
    public function __construct(Config $config, Repository $context)
46
    {
47
        $this->config = $config;
48
        $this->context = $context;
49
    }
50
51
    /**
52
     * @param  \Throwable  $e
53
     * @param  \Symfony\Component\HttpFoundation\Request  $request
54
     * @return array
55
     */
56
    public function make(Throwable $e, FoundationRequest $request = null) : array
57
    {
58
        $this->throwable = $e;
59
        $this->backtrace = $this->makeBacktrace();
60
        $this->request = $this->makeRequest($request);
61
        $this->environment = $this->makeEnvironment();
62
63
        return $this->format();
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    private function format() : array
70
    {
71
        return array_merge([], $this->config['notifier'], [
72
            'error' => [
73
                'class' => get_class($this->throwable),
74
                'message' => $this->throwable->getMessage(),
75
                'backtrace' => $this->backtrace->trace(),
76
                'causes' => $this->backtrace->previous(),
77
            ],
78
            'request' => [
79
                'cgi_data' => $this->environment->values(),
80
                'params' => $this->request->params(),
81
                'session' => $this->request->session(),
82
                'url' => $this->request->url(),
83
                'context' => $this->context->all(),
84
            ],
85
            'server' => [
86
                'pid' => getmypid(),
87
                'version' => $this->config['version'],
88
                'hostname' => $this->config['hostname'],
89
                'project_root' => $this->config['project_root'],
90
                'environment_name' => $this->config['environment_name'],
91
            ],
92
        ]);
93
    }
94
95
    /**
96
     * @return \Honeybadger\Environment
97
     */
98
    private function makeEnvironment() : Environment
99
    {
100
        return (new Environment)
101
            ->filterKeys($this->config['environment']['filter'])
102
            ->include($this->config['environment']['include']);
103
    }
104
105
    /**
106
     * @return \Honeybadger\BacktraceFactory
107
     */
108
    private function makeBacktrace() : BacktraceFactory
109
    {
110
        return new BacktraceFactory($this->throwable);
111
    }
112
113
    /**
114
     * @param  \Symfony\Component\HttpFoundation\Request  $request
115
     * @return \Honeybadger\Request
116
     */
117
    private function makeRequest(FoundationRequest $request = null) : Request
118
    {
119
        return (new Request($request))
120
            ->filterKeys($this->config['request']['filter']);
121
    }
122
}
123