DeleteShortUrlAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 5 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\ShortUrlIdentifier;
11
use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface;
12
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
13
14
class DeleteShortUrlAction extends AbstractRestAction
15
{
16
    protected const ROUTE_PATH = '/short-urls/{shortCode}';
17
    protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE];
18
19
    private DeleteShortUrlServiceInterface $deleteShortUrlService;
20
21 2
    public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService)
22
    {
23 2
        $this->deleteShortUrlService = $deleteShortUrlService;
24 2
    }
25
26 2
    public function handle(ServerRequestInterface $request): ResponseInterface
27
    {
28 2
        $identifier = ShortUrlIdentifier::fromApiRequest($request);
29 2
        $this->deleteShortUrlService->deleteByShortCode($identifier);
30 2
        return new EmptyResponse();
31
    }
32
}
33