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

DeleteArticleController::__construct()   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\Article;
4
5
use App\Entity\Article;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
9
use Symfony\Component\Routing\Annotation\Route;
10
11
/**
12
 * @Route("/api/articles/{slug}", name="api_articles_delete")
13
 * @Method("DELETE")
14
 *
15
 * @Security("is_granted('ROLE_USER') and is_granted('AUTHOR', article)")
16
 */
17
final class DeleteArticleController
18
{
19
    /**
20
     * @var EntityManagerInterface
21
     */
22
    private $entityManager;
23
24
    /**
25
     * @param EntityManagerInterface $manager
26
     */
27 3
    public function __construct(EntityManagerInterface $manager)
28
    {
29 3
        $this->entityManager = $manager;
30 3
    }
31
32
    /**
33
     * @param Article $article
34
     */
35 1
    public function __invoke(Article $article)
36
    {
37 1
        $this->entityManager->remove($article);
38 1
        $this->entityManager->flush();
39 1
    }
40
}
41