ListShortUrlsAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 5 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
6
7
use Laminas\Diactoros\Response\JsonResponse;
8
use Psr\Http\Message\ResponseInterface as Response;
9
use Psr\Http\Message\ServerRequestInterface as Request;
10
use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait;
11
use Shlinkio\Shlink\Core\Model\ShortUrlsParams;
12
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
13
use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer;
14
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
15
16
class ListShortUrlsAction extends AbstractRestAction
17
{
18
    use PaginatorUtilsTrait;
19
20
    protected const ROUTE_PATH = '/short-urls';
21
    protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
22
23
    private ShortUrlServiceInterface $shortUrlService;
24
    private array $domainConfig;
25
26 12
    public function __construct(ShortUrlServiceInterface $shortUrlService, array $domainConfig)
27
    {
28 12
        $this->shortUrlService = $shortUrlService;
29 12
        $this->domainConfig = $domainConfig;
30 12
    }
31
32 12
    public function handle(Request $request): Response
33
    {
34 12
        $shortUrls = $this->shortUrlService->listShortUrls(ShortUrlsParams::fromRawData($request->getQueryParams()));
35 12
        return new JsonResponse(['shortUrls' => $this->serializePaginator($shortUrls, new ShortUrlDataTransformer(
36 12
            $this->domainConfig,
37
        ))]);
38
    }
39
}
40