Passed
Pull Request — master (#1316)
by
unknown
32:07
created

UserInfoResponse   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 21
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generateHttpResponse() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\OAuth2\Server\ResponseTypes;
6
7
use League\OAuth2\Server\Entities\ClaimSetInterface;
8
use Psr\Http\Message\ResponseInterface;
9
10
use function json_encode;
11
12
/**
13
 * A simple user info response for the ResourceServer class
14
 *
15
 * @author Marc Riemer <[email protected]>
16
 */
17
class UserInfoResponse extends AbstractResponseType
18
{
19
    public function __construct(
20
        protected ClaimSetInterface $claimSet
21
    ) {
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function generateHttpResponse(ResponseInterface $response): ResponseInterface
28
    {
29
        $response = $response
30
            ->withStatus(200)
31
            ->withHeader('pragma', 'no-cache')
32
            ->withHeader('cache-control', 'no-store')
33
            ->withHeader('content-type', 'application/json; charset=UTF-8');
34
35
        $response->getBody()->write(json_encode($this->claimSet->getClaims()));
36
37
        return $response;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response returns the type Psr\Http\Message\MessageInterface which includes types incompatible with the type-hinted return Psr\Http\Message\ResponseInterface.
Loading history...
38
    }
39
}
40