ListShortUrlsAction::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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