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 ( 9f0f1f...360074 )
by Freek
26s queued 10s
created

CallWebhookJob::dispatchEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\WebhookServer;
4
5
use Exception;
6
use GuzzleHttp\Client;
7
use Illuminate\Support\Str;
8
use Illuminate\Bus\Queueable;
9
use Illuminate\Queue\SerializesModels;
10
use Illuminate\Queue\InteractsWithQueue;
11
use GuzzleHttp\Exception\RequestException;
12
use Illuminate\Contracts\Queue\ShouldQueue;
13
use Illuminate\Foundation\Bus\Dispatchable;
14
use Spatie\WebhookServer\Events\WebhookCallFailedEvent;
15
use Spatie\WebhookServer\Events\WebhookCallSucceededEvent;
16
use Spatie\WebhookServer\Events\FinalWebhookCallFailedEvent;
17
18
class CallWebhookJob implements ShouldQueue
19
{
20
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
21
22
    /** @var string */
23
    public $webhookUrl;
24
25
    /** @var string */
26
    public $httpVerb;
27
28
    /** @var int */
29
    public $tries;
30
31
    /** @var int */
32
    public $requestTimeout;
33
34
    /** @var string */
35
    public $backoffStrategyClass;
36
37
    /** @var string */
38
    public $signerClass;
39
40
    /** @var array */
41
    public $headers = [];
42
43
    /** @var bool */
44
    public $verifySsl;
45
46
    /** @var string */
47
    public $queue;
48
49
    /** @var array */
50
    public $payload = [];
51
52
    /** @var array */
53
    public $meta = [];
54
55
    /** @var array */
56
    public $tags = [];
57
58
    /** @var \GuzzleHttp\Psr7\Response|null */
59
    private $response;
60
61
	/**	@var string */
62
	private $errorType;
63
64
	/**	@var string */
65
	private $errorMessage;
66
67
    public function handle()
68
    {
69
        /** @var \GuzzleHttp\Client $client */
70
        $client = app(Client::class);
71
72
        $lastAttempt = $this->attempts() >= $this->tries;
73
74
        try {
75
            $this->response = $client->request($this->httpVerb, $this->webhookUrl, [
0 ignored issues
show
Documentation Bug introduced by
It seems like $client->request($this->...rs' => $this->headers)) of type object<Psr\Http\Message\ResponseInterface> is incompatible with the declared type object<GuzzleHttp\Psr7\Response>|null of property $response.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
76
                'timeout' => $this->requestTimeout,
77
                'body' => json_encode($this->payload),
78
                'verify' => $this->verifySsl,
79
                'headers' => $this->headers,
80
            ]);
81
82
            if (! Str::startsWith($this->response->getStatusCode(), 2)) {
83
                throw new Exception('Webhook call failed');
84
            }
85
86
            $this->dispatchEvent(WebhookCallSucceededEvent::class);
87
88
            return;
89
        } catch (Exception $exception) {
90
            if ($exception instanceof RequestException) {
91
                $this->response = $exception->getResponse();
0 ignored issues
show
Documentation Bug introduced by
It seems like $exception->getResponse() can also be of type object<Psr\Http\Message\ResponseInterface>. However, the property $response is declared as type object<GuzzleHttp\Psr7\Response>|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
92
				$this->errorType = get_class($exception);
93
				$this->errorMessage = $exception->getMessage();
94
            }
95
96
            if (! $lastAttempt) {
97
                /** @var \Spatie\WebhookServer\BackoffStrategy\BackoffStrategy $backoffStrategy */
98
                $backoffStrategy = app($this->backoffStrategyClass);
99
100
                $waitInSeconds = $backoffStrategy->waitInSecondsAfterAttempt($this->attempts());
101
102
                $this->release($waitInSeconds);
103
            }
104
105
            $this->dispatchEvent(WebhookCallFailedEvent::class);
106
        }
107
108
        if ($lastAttempt) {
109
            $this->dispatchEvent(FinalWebhookCallFailedEvent::class);
110
111
            $this->delete();
112
        }
113
    }
114
115
    public function tags()
116
    {
117
        return $this->tags;
118
    }
119
120
    public function getResponse()
121
    {
122
        return $this->response;
123
    }
124
125
    private function dispatchEvent(string $eventClass)
126
    {
127
        event(new $eventClass(
128
            $this->httpVerb,
129
            $this->webhookUrl,
130
            $this->payload,
131
            $this->headers,
132
            $this->meta,
133
            $this->tags,
134
            $this->attempts(),
135
            $this->response,
136
			$this->errorType,
137
			$this->errorMessage
138
        ));
139
    }
140
}
141