ClientSecretPost::getSupportedMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient\AuthMethod;
6
7
use function array_merge;
8
use function http_build_query;
9
use Psr\Http\Message\RequestInterface;
10
use TMV\OpenIdClient\Client\ClientInterface as OpenIDClient;
11
use TMV\OpenIdClient\Exception\InvalidArgumentException;
12
13
final class ClientSecretPost implements AuthMethodInterface
14
{
15 3
    public function getSupportedMethod(): string
16
    {
17 3
        return 'client_secret_post';
18
    }
19
20 2
    public function createRequest(
21
        RequestInterface $request,
22
        OpenIDClient $client,
23
        array $claims
24
    ): RequestInterface {
25 2
        $clientSecret = $client->getMetadata()->getClientSecret();
26
27 2
        if (null === $clientSecret) {
28 1
            throw new InvalidArgumentException($this->getSupportedMethod() . ' cannot be used without client_secret metadata');
29
        }
30
31 1
        $clientId = $client->getMetadata()->getClientId();
32
33 1
        $claims = array_merge($claims, [
34 1
            'client_id' => $clientId,
35 1
            'client_secret' => $clientSecret,
36
        ]);
37
38 1
        $request->getBody()->write(http_build_query($claims));
39
40 1
        return $request;
41
    }
42
}
43