Completed
Push — master ( 56e25c...088dd2 )
by Oleg
19:18
created

ResetIdMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 9 2
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Stdlib\Middleware;
5
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Server\MiddlewareInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
use SlayerBirden\DataFlowServer\Stdlib\Request\Parser;
11
12
final class ResetIdMiddleware implements MiddlewareInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $idName;
18
19 4
    public function __construct(string $idName = 'id')
20
    {
21 4
        $this->idName = $idName;
22 4
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27 4
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
28
    {
29 4
        $data = Parser::getRequestBody($request);
30 4
        if (isset($data[$this->idName])) {
31 4
            unset($data[$this->idName]);
32
        }
33
34 4
        return $handler->handle($request->withParsedBody($data));
35
    }
36
}
37