Passed
Push — master ( d346aa...fd2cec )
by Nicolas
04:54
created

GetCommentsListController::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controller\Comment;
4
5
use App\Entity\Article;
6
use App\Repository\CommentRepository;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8
use Symfony\Component\Routing\Annotation\Route;
9
10
/**
11
 * @Route("/api/articles/{slug}/comments", name="api_comments_list")
12
 * @Method("GET")
13
 */
14
final class GetCommentsListController
15
{
16
    /**
17
     * @var CommentRepository
18
     */
19
    private $commentRepository;
20
21
    /**
22
     * @param CommentRepository $repository
23
     */
24 1
    public function __construct(CommentRepository $repository)
25
    {
26 1
        $this->commentRepository = $repository;
27 1
    }
28
29
    /**
30
     * @param Article $article
31
     *
32
     * @return array
33
     */
34 1
    public function __invoke(Article $article)
35
    {
36 1
        return ['comments' => $this->commentRepository->findBy(['article' => $article])];
37
    }
38
}
39