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 (#97)
by Pierre
04:36
created

GuzzleClientFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B make() 0 11 5
1
<?php
2
3
namespace Spatie\UptimeMonitor;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\ConnectException;
7
use GuzzleHttp\Exception\TransferException;
8
use GuzzleHttp\HandlerStack;
9
use GuzzleHttp\Middleware;
10
use Psr\Http\Message\RequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12
13
/**
14
 * This is the guzzle factory class.
15
 *
16
 * @author Graham Campbell <[email protected]>
17
 */
18
final class GuzzleClientFactory
19
{
20
    public static function make(array $options = [], int $backoff = 1000): Client
21
    {
22
        $stack = HandlerStack::create();
23
        $stack->push(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, TransferException $exception = null) {
24
            return $retries < 3 && ($exception instanceof ConnectException || ($response && ($response->getStatusCode() >= 500 || $response->getStatusCode() === 429)));
25
        }, function ($retries) use ($backoff) {
26
            return (int) 2 ** $retries * $backoff;
27
        }));
28
29
        return new Client(array_merge(['handler' => $stack, 'connect_timeout' => 10, 'timeout' => 15], $options));
30
    }
31
}
32