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
Push — master ( 1b55dd...b5a5fd )
by Pascal
01:11
created

Event::getRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ProtoneMedia\LaravelPaddle\Events;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Str;
7
8
abstract class Event
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $webhookData;
14
15
    /**
16
     * @var \Illuminate\Http\Request
17
     */
18
    protected $request;
19
20
    public function __construct(array $webhookData, Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
21
    {
22
        $this->webhookData = $webhookData;
23
        $this->request     = $request;
24
    }
25
26
    /**
27
     * Getter for all data.
28
     *
29
     * @return array
30
     */
31
    public function all(): array
32
    {
33
        return $this->webhookData;
34
    }
35
36
    /**
37
     * Getter for the request.
38
     *
39
     * @return \Illuminate\Http\Request
40
     */
41
    public function getRequest(): Request
42
    {
43
        return $this->request;
44
    }
45
46
    /**
47
     * Getter for the webhook data.
48
     *
49
     * @param  string $key
50
     * @return mixed
51
     */
52
    public function __get(string $key)
53
    {
54
        $value = $this->webhookData[$key];
55
56
        if ($key === 'passthrough') {
57
            $result = json_decode($value, true);
58
59
            if (json_last_error() === JSON_ERROR_NONE) {
60
                return $result;
61
            }
62
        }
63
64
        return $value;
65
    }
66
67
    /**
68
     * Determine if an attribute exists on the webhook data.
69
     *
70
     * @param  string $key
71
     * @return bool
72
     */
73
    public function __isset($key)
74
    {
75
        return isset($this->webhookData[$key]);
76
    }
77
78
    /**
79
     * Generates the event class name with the 'alert_name' attribute from
80
     * the data and fires the event with the data.
81
     *
82
     * @param  array  $data
83
     * @param  \Illuminate\Http\Request  $request
84
     * @return void
85
     */
86
    public static function fire(array $data, Request $request)
87
    {
88
        $event = Str::studly($data['alert_name'] ?? 'generic_webhook');
89
90
        $eventClass = __NAMESPACE__ . '\\' . $event;
91
92
        return event(new $eventClass($data, $request));
93
    }
94
}
95