Completed
Push — develop ( 8162da...f53fa5 )
by Alejandro
31s queued 13s
created

DefaultShortCodesLengthMiddleware   A

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
eloc 7
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
wmc 3

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 2
    public function __construct(int $defaultShortCodesLength)
18
    {
19 2
        $this->defaultShortCodesLength = $defaultShortCodesLength;
20
    }
21
22 2
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
23
    {
24 2
        $body = $request->getParsedBody();
25 2
        if (! isset($body[ShortUrlMetaInputFilter::SHORT_CODE_LENGTH])) {
26 1
            $body[ShortUrlMetaInputFilter::SHORT_CODE_LENGTH] = $this->defaultShortCodesLength;
27
        }
28
29 2
        return $handler->handle($request->withParsedBody($body));
30
    }
31
}
32