Passed
Branch develop (7f369c)
by Nicolas
04:24
created

CommentsListController::__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\Api;
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
 * CommentsListController.
12
 *
13
 * @Route("/api/articles/{slug}/comments", name="api_comments_list")
14
 * @Method("GET")
15
 */
16
class CommentsListController
17
{
18
    /**
19
     * @var CommentRepository
20
     */
21
    private $repository;
22
23
    /**
24
     * @param CommentRepository $repository
25
     */
26 1
    public function __construct(CommentRepository $repository)
27
    {
28 1
        $this->repository = $repository;
29 1
    }
30
31
    /**
32
     * @param Article $article
33
     *
34
     * @return array
35
     */
36 1
    public function __invoke(Article $article)
37
    {
38 1
        return ['comments' => $this->repository->findBy(['article' => $article])];
39
    }
40
}
41