ClientSecretBasic   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 27
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedMethod() 0 3 1
A createRequest() 0 20 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\AuthMethod;
6
7
use function base64_encode;
8
use Facile\OpenIDClient\Client\ClientInterface as OpenIDClient;
9
use Facile\OpenIDClient\Exception\InvalidArgumentException;
10
use function http_build_query;
11
use Psr\Http\Message\RequestInterface;
12
13
final class ClientSecretBasic implements AuthMethodInterface
14
{
15 3
    public function getSupportedMethod(): string
16
    {
17 3
        return 'client_secret_basic';
18
    }
19
20 2
    public function createRequest(
21
        RequestInterface $request,
22
        OpenIDClient $client,
23
        array $claims
24
    ): RequestInterface {
25 2
        $clientId = $client->getMetadata()->getClientId();
26 2
        $clientSecret = $client->getMetadata()->getClientSecret();
27
28 2
        if (null === $clientSecret) {
29 1
            throw new InvalidArgumentException($this->getSupportedMethod() . ' cannot be used without client_secret metadata');
30
        }
31
32 1
        $request = $request->withHeader(
33 1
            'Authorization',
34 1
            'Basic ' . base64_encode(urlencode($clientId) . ':' . urlencode($clientSecret))
35
        );
36
37 1
        $request->getBody()->write(http_build_query($claims));
38
39 1
        return $request;
40
    }
41
}
42