AdminOrderController::deleteAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Cart\Cart;
6
use AppBundle\Cart\CartSerializer;
7
use AppBundle\Entity\Order;
8
use AppBundle\Event\OrderEvent;
9
use AppBundle\Event\OrderEvents;
10
use AppBundle\Form\Type\OrderType;
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
12
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
13
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Response;
16
17
class AdminOrderController extends Controller
18
{
19
    /**
20
     * @Route(path="/admin/commandes", name="admin_order_index")
21
     */
22
    public function indexAction()
23
    {
24
        return $this->render('admin_order/index.html.twig', array(
25
            'orders' => $this->getDoctrine()->getRepository(Order::class)->findLatest()
26
        ));
27
    }
28
29
    /**
30
     * @Route(path="/admin/commandes/{id}", name="admin_order_show")
31
     * @ParamConverter
32
     */
33
    public function showAction(Order $order)
34
    {
35
        return $this->render('admin_order/show.html.twig', array(
36
            'order' => $order
37
        ));
38
    }
39
40
    /**
41
     * @Route(path="/admin/commandes/{id}/supprimer", name="admin_order_delete")
42
     * @ParamConverter
43
     */
44 View Code Duplication
    public function deleteAction(Request $request, Order $order)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        if ($request->isMethod('POST')) {
47
            $em = $this->getDoctrine()->getManager();
48
            $em->remove($order);
49
            $em->flush();
50
51
            $request->getSession()->getFlashBag()->add('success', 'La commande de '.$order->getFullname().' a bien été supprimée.');
52
53
            return $this->redirectToRoute('admin_order_index');
54
        }
55
56
        return $this->render('admin_order/delete.html.twig', array(
57
            'order' => $order
58
        ));
59
    }
60
}
61