Test Failed
Branch develop (7f369c)
by Nicolas
04:26
created

CommentsDeleteController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
namespace App\Controller\Api;
4
5
use App\Entity\Comment;
6
use Doctrine\ORM\EntityManagerInterface;
7
use FOS\RestBundle\Controller\Annotations\View;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
10
use Symfony\Component\Routing\Annotation\Route;
11
12
/**
13
 * CommentsDeleteController.
14
 *
15
 * @Route("/api/articles/{slug}/comments/{id}", name="api_comments_delete")
16
 * @Method("DELETE")
17
 * @View(statusCode=204)
18
 * @IsGranted("OWNER", subject="comment")
19
 */
20
class CommentsDeleteController
21
{
22
    /**
23
     * @var EntityManagerInterface
24
     */
25
    private $manager;
26
27
    /**
28
     * @param EntityManagerInterface $manager
29
     */
30
    public function __construct(EntityManagerInterface $manager)
31
    {
32
        $this->manager = $manager;
33
    }
34
35
    /**
36
     * @param Comment $comment
37
     */
38
    public function __invoke(Comment $comment)
39
    {
40
        $this->manager->remove($comment);
41
        $this->manager->flush();
42
    }
43
}
44