CommentsQueryController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLatestComments() 0 6 1
A __construct() 0 4 1
A getCommentsForPost() 0 5 1
1
<?php
2
3
namespace App\Modules\Comments\Api\Controller;
4
5
use App\Modules\Comments\Api\CommentsApiInterface;
6
use App\Modules\Comments\Api\Query\FindCommentsByPostIdQuery;
7
use App\Modules\Comments\Api\Query\FindLatestCommentsQuery;
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\Routing\Annotation\Route;
12
use Symfony\Component\Uid\Ulid;
13
14
#[Route('/api/comments')]
15
class CommentsQueryController extends AbstractController
16
{
17
    /**
18
     * @param CommentsApiInterface $commentsApi
19
     */
20 1
    public function __construct(
21
        private CommentsApiInterface $commentsApi
22
    )
23
    {
24 1
    }
25
26
    /**
27
     * @param string $postId
28
     * @return Response
29
     */
30 1
    #[Route('/{postId}', methods: ['GET'])]
31
    public function getCommentsForPost(string $postId): Response
32
    {
33 1
        return $this->json(
34 1
            $this->commentsApi->findCommentsForPost(new FindCommentsByPostIdQuery(new Ulid($postId)))
35
        );
36
    }
37
38
    /**
39
     * @param Request $request
40
     * @return Response
41
     */
42 1
    #[Route('/', methods: ['GET'])]
43
    public function getLatestComments(Request $request): Response
44
    {
45 1
        $pageNo = $request->query->get("pageNo", "1");
46 1
        return $this->json(
47 1
            $this->commentsApi->findLatestComments(new FindLatestCommentsQuery(intval($pageNo)))
48
        );
49
    }
50
}