ClientSecretPost::createRequest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
nc 2
nop 3
dl 0
loc 21
ccs 10
cts 10
cp 1
crap 2
rs 9.9666
c 1
b 0
f 0
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