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.

Clearbit   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 93.94%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 3
dl 0
loc 77
ccs 31
cts 33
cp 0.9394
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A setKey() 0 5 1
A setClient() 0 4 1
A createEnrichmentApi() 0 4 1
A enrichmentApi() 0 4 1
A createNameToDomain() 0 4 1
A nameToDomain() 0 4 1
A validateKey() 0 12 3
A getKey() 0 4 2
1
<?php
2
3
namespace wlbrough\clearbit;
4
5
use wlbrough\clearbit\Exceptions\ClearbitException;
6
7
class Clearbit
8
{
9
    private static $clearbitKey = null;
10
    private static $httpClient = null;
11
12
    private $instanceKey;
13
14
    /**
15
     * Clearbit constructor.
16
     *
17
     * @param $key Clearbit API Key
18
     * @throws ClearbitException
19
     */
20 27
    public function __construct($key = null)
21
    {
22 27
        if ($key === null) {
23 18
            if (self::$clearbitKey === null) {
24 3
                $msg = 'No token provided and none globally set. ';
25 3
                $msg .= 'Use Clearbit::setKey, or instantiate the Clearbit class with a $clearbit_key parameter.';
26
27 8
                throw new ClearbitException($msg);
28
            }
29 10
        } else {
30 9
            self::validateKey($key);
31 9
            $this->instanceKey = $key;
32
        }
33 24
    }
34
35 66
    public static function setKey($key)
36
    {
37 66
        self::validateKey($key);
38 48
        self::$clearbitKey = $key;
39 48
    }
40
41 24
    public static function setClient($client)
42
    {
43 24
        self::$httpClient = $client;
44 24
    }
45
46 21
    public static function createEnrichmentApi()
47
    {
48 21
        return new EnrichmentApi(self::$clearbitKey, self::$httpClient);
49
    }
50
51 3
    public function enrichmentApi()
52
    {
53 3
        return new EnrichmentApi($this->getKey(), self::$httpClient);
54
    }
55
56 6
    public static function createNameToDomain()
57
    {
58 6
        return new NameToDomainApi(self::$clearbitKey, self::$httpClient);
59
    }
60
61
    public function nameToDomain()
62
    {
63
        return new NameToDomainApi($this->getKey(), self::$httpClient);
64
    }
65
66 69
    private static function validateKey($key)
67
    {
68 69
        if (!is_string($key)) {
69 9
            throw new \InvalidArgumentException('Key is not a string');
70
        }
71
72 60
        if (strlen($key) < 4) {
73 9
            throw new \InvalidArgumentException('Token too short');
74
        }
75
76 51
        return true;
77
    }
78
79 9
    public function getKey()
80
    {
81 9
        return $this->instanceKey ?: self::$clearbitKey;
82
    }
83
}
84