Passed
Push — master ( 904589...078d26 )
by Thomas Mauro
02:52
created

ClientSecretPost::createRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

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