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

DeleteCommentController::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
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\Comment;
6
use Doctrine\ORM\EntityManagerInterface;
7
use FOS\RestBundle\Controller\Annotations\View;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
10
use Symfony\Component\Routing\Annotation\Route;
11
12
/**
13
 * @Route("/api/articles/{slug}/comments/{id}", name="api_comments_delete")
14
 * @Method("DELETE")
15
 *
16
 * @View(statusCode=204)
17
 *
18
 * @Security("is_granted('ROLE_USER') and is_granted('AUTHOR', comment)")
19
 */
20
final class DeleteCommentController
21
{
22
    /**
23
     * @var EntityManagerInterface
24
     */
25
    private $entityManager;
26
27
    /**
28
     * @param EntityManagerInterface $manager
29
     */
30 3
    public function __construct(EntityManagerInterface $manager)
31
    {
32 3
        $this->entityManager = $manager;
33 3
    }
34
35
    /**
36
     * @param Comment $comment
37
     */
38 1
    public function __invoke(Comment $comment)
39
    {
40 1
        $this->entityManager->remove($comment);
41 1
        $this->entityManager->flush();
42 1
    }
43
}
44