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

ArticlesDeleteController::__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 2
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\Api;
4
5
use App\Entity\Article;
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
use Symfony\Component\Security\Core\User\UserInterface;
12
13
/**
14
 * ArticlesDeleteController.
15
 *
16
 * @Route("/api/articles/{slug}", name="api_articles_delete")
17
 * @Method("DELETE")
18
 * @View(statusCode=204)
19
 * @IsGranted("OWNER", subject="article")
20
 */
21
class ArticlesDeleteController
22
{
23
    /**
24
     * @var EntityManagerInterface
25
     */
26
    protected $manager;
27
28
    /**
29
     * @param EntityManagerInterface $manager
30
     */
31 2
    public function __construct(EntityManagerInterface $manager)
32
    {
33 2
        $this->manager = $manager;
34 2
    }
35
36
    /**
37
     * @param UserInterface $user
38
     * @param Article       $article
39
     */
40 1
    public function __invoke(UserInterface $user, Article $article)
41
    {
42 1
        $this->manager->remove($article);
43 1
        $this->manager->flush();
44 1
    }
45
}
46