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.
Failed Conditions
Pull Request — master (#1)
by Harald
04:14 queued 01:30
created

AuthenticatedApi::isReady()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 16
ccs 0
cts 14
cp 0
crap 12
rs 9.9666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Bokbasen\ApiClient;
4
5
use Bokbasen\ApiClient\Exceptions\MissingParameterException;
6
use Psr\Cache\CacheItemPoolInterface;
7
use Psr\Http\Message\ResponseInterface;
8
9
abstract class AuthenticatedApi
10
{
11
    /**
12
     * @var string
13
     */
14
    private $loginEndpoint;
15
16
    /**
17
     * @var string
18
     */
19
    private $loginUsername;
20
21
    /**
22
     * @var string
23
     */
24
    private $loginPassword;
25
26
    /**
27
     * @var Client
28
     */
29
    private $client;
30
31
    /**
32
     * @var CacheItemPoolInterface
33
     */
34
    protected $cache;
35
36
    /**
37
     * @var LoggerInterface
0 ignored issues
show
Bug introduced by
The type Bokbasen\ApiClient\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
     */
39
    protected $logger;
40
41
    /**
42
     * @var string
43
     */
44
    protected $endpoint;
45
46
    public function get(string $path, array $headers = [], bool $authenticate = true): ResponseInterface
47
    {
48
        return $this->getClient()->get($path, $headers, $authenticate);
49
    }
50
51
    public function post(string $path, $body, array $headers = [], $authenticate = true): ResponseInterface
52
    {
53
        return $this->getClient()->post($path, $body, $headers, $authenticate);
54
    }
55
56
    public function patch(string $path, $body, array $headers = [], bool $authenticate = true): ResponseInterface
57
    {
58
        return $this->getClient()->patch($path, $body, $headers, $authenticate);
59
    }
60
61
    public function put(string $path, $body, array $headers = [], $authenticate = true): ResponseInterface
62
    {
63
        return $this->getClient()->put($path, $body, $headers, $authenticate);
64
    }
65
66
    protected function getClient(): Client
67
    {
68
        $this->isReady();
69
70
        if (!$this->client) {
71
            $login = new Login($this->loginUsername, $this->password, $this->loginEndpoint, $this->cache, $this->logger);
0 ignored issues
show
Bug introduced by
The type Bokbasen\ApiClient\Login was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
            $this->client = new Client($login, $this->orderEndpoint);
0 ignored issues
show
Bug Best Practice introduced by
The property orderEndpoint does not exist on Bokbasen\ApiClient\AuthenticatedApi. Did you maybe forget to declare it?
Loading history...
73
        }
74
75
        return $this->client;
76
    }
77
78
    public function setEndpoint(string $endpoint): void
79
    {
80
        $this->endpoint = $endpoint;
81
    }
82
83
    public function setCredentials(string $username, string $password, string $endpoint): void
84
    {
85
        $this->username = $username;
0 ignored issues
show
Bug Best Practice introduced by
The property username does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
86
        $this->password = $password;
0 ignored issues
show
Bug Best Practice introduced by
The property password does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
87
        $this->loginEndpoint = sprintf('%s/v1/tickets', $endpoint);
88
    }
89
90
    public function setLogger(LoggerInterface $logger = null): void
91
    {
92
        $this->logger = $logger;
93
    }
94
95
    public function setCache(CacheItemPoolInterface $cacheItemPool = null): void
96
    {
97
        $this->cache = $cacheItemPool;
98
    }
99
100
    private function isReady(): bool
101
    {
102
        $params = [
103
            'loginEndpoint',
104
            'loginUsername',
105
            'loginPassword',
106
            'endpoint',
107
        ];
108
109
        foreach ($params as $param) {
110
            if (!$this->$param) {
111
                throw new MissingParameterException($param);
112
            }
113
        }
114
115
        return true;
116
    }
117
}
118