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 (#75)
by Kaname
02:00
created

Request::getOptionsByKey()   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 Honeybadger\Concerns\FiltersData;
6
use Symfony\Component\HttpFoundation\Request as FoundationRequest;
7
8
class Request
9
{
10
    use FiltersData;
11
12
    /**
13
     * @var \Symfony\Component\HttpFoundation\Request
14
     */
15
    protected $request;
16
17
    /**
18
     * @var array
19
     */
20
    protected $options;
21
22
    /**
23
     * @param  \Symfony\Component\HttpFoundation\Request  $request
24
     * @param  array  $options
25
     */
26
    public function __construct(FoundationRequest $request = null, array $options = [])
27
    {
28
        $this->request = $request ?? FoundationRequest::createFromGlobals();
29
        $this->options = $options;
30
31
        $this->keysToFilter = [
32
            'password',
33
            'password_confirmation',
34
        ];
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function url() : string
41
    {
42
        return $this->httpRequest()
43
            ? $this->request->getUri()
44
            : '';
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function params() : array
51
    {
52
        if (! $this->httpRequest()) {
53
            return [];
54
        }
55
56
        return [
57
            'method' => $this->request->getMethod(),
58
            'query' => $this->filter($this->request->query->all()),
59
            'data' => $this->filter($this->data()),
60
        ];
61
    }
62
63
    /**
64
     * @return array
65
     */
66
    public function session() : array
67
    {
68
        return $this->request->hasSession() && $this->request->getSession()
69
            ? $this->filter($this->request->getSession()->all())
70
            : [];
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function component() : string
77
    {
78
        return $this->getOptionsByKey('component');
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function action() : string
85
    {
86
        return $this->getOptionsByKey('action');
87
    }
88
89
    /**
90
     * @return bool
91
     */
92
    private function httpRequest() : bool
93
    {
94
        return isset($_SERVER['REQUEST_METHOD']);
95
    }
96
97
    /**
98
     * @return array
99
     */
100
    private function data() : array
101
    {
102
        if ($this->request->getContentType() === 'json') {
103
            return json_decode($this->request->getContent(), true) ?: [];
104
        }
105
106
        if ($this->request->getContentType() === 'form') {
107
            return $this->request->request->all();
108
        }
109
110
        return [];
111
    }
112
113
    private function getOptionsByKey($key) : string
114
    {
115
        return isset($this->options[$key]) ? $this->options[$key] : '';
116
    }
117
}
118