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
07:59 queued 03:39
created

AuthenticatedApi::setEndpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
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\Http\Message\ResponseInterface;
7
8
abstract class AuthenticatedApi
9
{
10
    /**
11
     * @var string
12
     */
13
    private $loginEndpoint;
14
15
    /**
16
     * @var string
17
     */
18
    private $loginUsername;
19
20
    /**
21
     * @var string
22
     */
23
    private $loginPassword;
24
25
    /**
26
     * @var Client
27
     */
28
    private $client;
29
30
    /**
31
     * @var CacheItemPoolInterface
0 ignored issues
show
Bug introduced by
The type Bokbasen\ApiClient\CacheItemPoolInterface 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...
32
     */
33
    protected $cache;
34
35
    /**
36
     * @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...
37
     */
38
    protected $logger;
39
40
    /**
41
     * @var string
42
     */
43
    protected $endpoint;
44
45
    public function get(string $path, array $headers = [], bool $authenticate = true): ResponseInterface
46
    {
47
        return $this->getClient()->get($path, $headers, $authenticate);
48
    }
49
50
    public function post(string $path, $body, array $headers = [], $authenticate = true): ResponseInterface
51
    {
52
        return $this->getClient()->post($path, $body, $headers, $authenticate);
53
    }
54
55
    public function patch(string $path, array $headers = [], bool $authenticate = true): ResponseInterface
56
    {
57
        return $this->getClient()->patch($path, $headers, $authenticate);
0 ignored issues
show
Bug introduced by
$authenticate of type boolean is incompatible with the type array expected by parameter $headers of Bokbasen\ApiClient\Client::patch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        return $this->getClient()->patch($path, $headers, /** @scrutinizer ignore-type */ $authenticate);
Loading history...
58
    }
59
60
    public function put(string $path, $body, array $headers = [], $authenticate = true): ResponseInterface
61
    {
62
        return $this->getClient()->put($path, $body, $headers, $authenticate);
63
    }
64
65
    protected function getClient(): Client
66
    {
67
        $this->isReady();
68
69
        if (!$this->client) {
70
            $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...
71
            $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...
72
        }
73
74
        return $this->client;
75
    }
76
77
    public function setEndpoint(string $endpoint): void
78
    {
79
        $this->endpoint = $endpoint;
80
    }
81
82
    public function setCredentials(string $username, string $password, string $endpoint): void
83
    {
84
        $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...
85
        $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...
86
        $this->loginEndpoint = sprintf('%s/v1/tickets', $endpoint);
87
    }
88
89
    public function setLogger(LoggerInterface $logger = null): void
90
    {
91
        $this->logger = $logger;
92
    }
93
94
    public function setCache(CacheItemPoolInterface $cacheItemPool = null): void
95
    {
96
        $this->cache = $cacheItemPool;
97
    }
98
99
    private function isReady(): bool
100
    {
101
        $params = [
102
            'loginEndpoint',
103
            'loginUsername',
104
            'loginPassword',
105
            'endpoint',
106
        ];
107
108
        foreach ($params as $param) {
109
            if (!$this->$param) {
110
                throw new MissingParameterException($param);
111
            }
112
        }
113
114
        return true;
115
    }
116
}
117