Completed
Pull Request — master (#647)
by Alejandro
04:12
created

ListShortUrlsAction::determineDateRangeFromQuery()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
ccs 4
cts 4
cp 1
crap 3
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 Psr\Log\LoggerInterface;
11
use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait;
12
use Shlinkio\Shlink\Core\Model\ShortUrlsParams;
13
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
14
use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer;
15
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
16
17
class ListShortUrlsAction extends AbstractRestAction
18
{
19
    use PaginatorUtilsTrait;
20
21
    protected const ROUTE_PATH = '/short-urls';
22
    protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
23
24
    private ShortUrlServiceInterface $shortUrlService;
25
    private array $domainConfig;
26
27 11
    public function __construct(
28
        ShortUrlServiceInterface $shortUrlService,
29
        array $domainConfig,
30
        ?LoggerInterface $logger = null
31
    ) {
32 11
        parent::__construct($logger);
33 11
        $this->shortUrlService = $shortUrlService;
34 11
        $this->domainConfig = $domainConfig;
35
    }
36
37 11
    public function handle(Request $request): Response
38
    {
39 11
        $shortUrls = $this->shortUrlService->listShortUrls(ShortUrlsParams::fromRawData($request->getQueryParams()));
40 11
        return new JsonResponse(['shortUrls' => $this->serializePaginator($shortUrls, new ShortUrlDataTransformer(
41 11
            $this->domainConfig,
42
        ))]);
43
    }
44
}
45