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

DeleteArticleController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 6
cts 6
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 4 1
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