ClientConfigurationDeleteEndpoint   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 29
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\ClientConfigurationEndpoint;
15
16
use OAuth2Framework\Component\Core\Client\Client;
17
use OAuth2Framework\Component\Core\Client\ClientRepository;
18
use Psr\Http\Message\ResponseFactoryInterface;
19
use Psr\Http\Message\ResponseInterface;
20
use Psr\Http\Message\ServerRequestInterface;
21
use Psr\Http\Server\MiddlewareInterface;
22
use Psr\Http\Server\RequestHandlerInterface;
23
24
final class ClientConfigurationDeleteEndpoint implements MiddlewareInterface
25
{
26
    /**
27
     * @var ClientRepository
28
     */
29
    private $clientRepository;
30
31
    /**
32
     * @var ResponseFactoryInterface
33
     */
34
    private $responseFactory;
35
36
    public function __construct(ClientRepository $clientRepository, ResponseFactoryInterface $responseFactory)
37
    {
38
        $this->clientRepository = $clientRepository;
39
        $this->responseFactory = $responseFactory;
40
    }
41
42
    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
43
    {
44
        /** @var Client $client */
45
        $client = $request->getAttribute('client');
46
        $client->markAsDeleted();
47
        $this->clientRepository->save($client);
48
49
        $response = $this->responseFactory->createResponse(204);
50
        $response = $response->withHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate, private');
51
52
        return $response->withHeader('Pragma', 'no-cache, no-store');
53
    }
54
}
55