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.

Api   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 67.65%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 2
dl 0
loc 64
ccs 23
cts 34
cp 0.6765
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setWebhookEndpoint() 0 5 1
A enableStreaming() 0 4 1
A validateUrl() 0 14 3
A call() 0 17 3
A post() 0 13 2
1
<?php
2
3
namespace wlbrough\clearbit\Abstracts;
4
5
use GuzzleHttp\Client;
6
use wlbrough\clearbit\Exceptions\ApiException;
7
8
abstract class Api
9
{
10
    protected $endpointUrl = null;
11
    protected $useStreaming = false;
12
    protected $httpClient = null;
13
14 27
    public function setWebhookEndpoint($endpointUrl = null)
15
    {
16 27
        self::validateUrl($endpointUrl);
17 12
        $this->endpointUrl = $endpointUrl;
18 12
    }
19
20 3
    public function enableStreaming()
21
    {
22 3
        $this->useStreaming = true;
23 3
    }
24
25 27
    private static function validateUrl($url)
26
    {
27 27
        if (!is_string($url)) {
28 9
            throw new \InvalidArgumentException('Webhook endpoint is not a string');
29
        }
30
31 18
        $isValid = preg_match('#((https?|ftp)://(\S*?\.\S*?))([\s)\[\]{},;"\':<]|\.\s|$)#i', $url);
32
33 18
        if (!$isValid) {
34 6
            throw new \InvalidArgumentException('Webhook endpoint is not a URL');
35
        }
36
37 12
        return true;
38
    }
39
40 24
    protected static function call($url, $client)
41
    {
42 24
        if (!$client) {
43
            $client = new Client(['http_errors' => false]);
44
        }
45
46 24
        $response = $client->get($url);
47 24
        $status = $response->getStatusCode();
48
49 24
        if ($status === 200) {
50 12
            $returnData = json_decode($response->getBody());
51 8
        } else {
52 12
            throw new ApiException($status);
53
        }
54
55 12
        return $returnData;
56
    }
57
58
    protected static function post($url, $body, $successCode = 200, $client = null)
59
    {
60
        if (!$client) {
61
            $client = new Client(['http_errors' => false]);
62
        }
63
64
        $response = $client->post($url, [
65
            'form_params' => $body
66
        ]);
67
        $status = $response->getStatusCode();
68
69
        return $status === $successCode;
70
    }
71
}
72