EditShortUrlAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
6
7
use Laminas\Diactoros\Response\EmptyResponse;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Shlinkio\Shlink\Core\Model\ShortUrlEdit;
11
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
12
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
13
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
14
15
class EditShortUrlAction extends AbstractRestAction
16
{
17
    protected const ROUTE_PATH = '/short-urls/{shortCode}';
18
    protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PATCH, self::METHOD_PUT];
19
20
    private ShortUrlServiceInterface $shortUrlService;
21
22 3
    public function __construct(ShortUrlServiceInterface $shortUrlService)
23
    {
24 3
        $this->shortUrlService = $shortUrlService;
25 3
    }
26
27 3
    public function handle(ServerRequestInterface $request): ResponseInterface
28
    {
29 3
        $shortUrlEdit = ShortUrlEdit::fromRawData((array) $request->getParsedBody());
30 2
        $identifier = ShortUrlIdentifier::fromApiRequest($request);
31
32 2
        $this->shortUrlService->updateMetadataByShortCode($identifier, $shortUrlEdit);
33 2
        return new EmptyResponse();
34
    }
35
}
36