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

CommentsListController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 3 1
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