DefaultShortCodesLengthMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Rest\Middleware\ShortUrl;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Shlinkio\Shlink\Core\Validation\ShortUrlMetaInputFilter;
12
13
class DefaultShortCodesLengthMiddleware implements MiddlewareInterface
14
{
15
    private int $defaultShortCodesLength;
16
17 3
    public function __construct(int $defaultShortCodesLength)
18
    {
19 3
        $this->defaultShortCodesLength = $defaultShortCodesLength;
20 3
    }
21
22 3
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
23
    {
24 3
        $body = $request->getParsedBody();
25 3
        if (! isset($body[ShortUrlMetaInputFilter::SHORT_CODE_LENGTH])) {
26 2
            $body[ShortUrlMetaInputFilter::SHORT_CODE_LENGTH] = $this->defaultShortCodesLength;
27
        }
28
29 3
        return $handler->handle($request->withParsedBody($body));
30
    }
31
}
32