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
|
|||
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
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
72 | $this->client = new Client($login, $this->orderEndpoint); |
||
0 ignored issues
–
show
|
|||
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
|
|||
86 | $this->password = $password; |
||
0 ignored issues
–
show
|
|||
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 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths