EditShortUrlAction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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