Completed
Push — develop ( ae060f...1a4eee )
by Alejandro
08:12 queued 08:08
created

TagVisitsAction   A

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 10
dl 0
loc 21
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Rest\Action\Visit;
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\VisitsParams;
12
use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface;
13
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
14
15
class TagVisitsAction extends AbstractRestAction
16
{
17
    use PaginatorUtilsTrait;
18
19
    protected const ROUTE_PATH = '/tags/{tag}/visits';
20
    protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET];
21
22
    private VisitsTrackerInterface $visitsTracker;
23
24 1
    public function __construct(VisitsTrackerInterface $visitsTracker)
25
    {
26 1
        $this->visitsTracker = $visitsTracker;
27
    }
28
29 1
    public function handle(Request $request): Response
30
    {
31 1
        $tag = $request->getAttribute('tag', '');
32 1
        $visits = $this->visitsTracker->visitsForTag($tag, VisitsParams::fromRawData($request->getQueryParams()));
33
34 1
        return new JsonResponse([
35 1
            'visits' => $this->serializePaginator($visits),
36
        ]);
37
    }
38
}
39