Endpoint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 14
c 0
b 0
f 0
dl 0
loc 30
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getAccountPrivateKey() 0 3 1
A logResponse() 0 8 1
A createKeyId() 0 8 1
1
<?php
2
3
namespace Rogierw\RwAcme\Endpoints;
4
5
use Rogierw\RwAcme\Api;
6
use Rogierw\RwAcme\Http\Response;
7
use Rogierw\RwAcme\Support\KeyId;
8
9
abstract class Endpoint
10
{
11
    public function __construct(protected Api $client)
12
    {
13
    }
14
15
    protected function createKeyId(string $accountUrl, string $url, ?array $payload = null): array
16
    {
17
        return KeyId::generate(
18
            $this->client->localAccount()->getPrivateKey(),
19
            $accountUrl,
20
            $url,
21
            $this->client->nonce()->getNew(),
22
            $payload
23
        );
24
    }
25
26
    protected function getAccountPrivateKey(): string
27
    {
28
        return $this->client->localAccount()->getPrivateKey();
29
    }
30
31
    protected function logResponse(string $level, string $message, Response $response, array $additionalContext = []): void
32
    {
33
        $this->client->logger($level, $message, array_merge([
34
            'url' => $response->getRequestedUrl(),
35
            'status' => $response->getHttpResponseCode(),
36
            'headers' => $response->getHeaders(),
37
            'body' => $response->getBody(),
38
        ], $additionalContext));
39
    }
40
}
41