Completed
Pull Request — master (#2)
by Andrew
03:11
created

AdminCategoryController::createDeleteForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 8
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 2
1
<?php
2
3
namespace AppBundle\Controller\Admin;
4
5
use AppBundle\Entity\Category;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\Request;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
10
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
12
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
13
use AppBundle\Form\CategoryType;
14
15
16
17
/**
18
 * @Security("has_role('ROLE_MANAGER')")
19
 * @Route("/admin")
20
 */
21
class AdminCategoryController extends Controller
22
{
23
    /**
24
     * @Route("/categories", name="admin_categories")
25
     * @Method("GET")
26
     */
27
    public function categoriesAction(Request $request)
28
    {
29
        $em = $this->getDoctrine()->getManager()->getRepository('AppBundle\Entity\Category');
30
        $categories = $em->childrenHierarchy();
31
        return $this->render("@App/admin/category/categories.html.twig", ['categories' => $categories]);
32
    }
33
34
    /**
35
     * @Route("/category_root/new", name="admin_category_root_new")
36
     * @Method({"GET", "POST"})
37
     * @Security("has_role('ROLE_ADMIN')")
38
     */
39 View Code Duplication
    public function newCategoryRootAction(Request $request)
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...
40
    {
41
        $entityManager = $this->getDoctrine()->getManager();
42
        $category = new Category();
43
        $form = $this->createForm(CategoryType::class, $category);
44
        $form->handleRequest($request);
45
        if ($form->isSubmitted() && $form->isValid()) {
46
            $category->setParent(null);
47
            $entityManager->persist($category);
48
            $entityManager->flush();
49
            return $this->redirectToRoute('admin_categories');
50
        }
51
        return $this->render('@App/admin/category/new_category_root.html.twig', array(
52
            'category' => $category,
53
            'form' => $form->createView(),
54
        ));
55
    }
56
57
58
59
60 View Code Duplication
    private function createDeleteForm(Category $category)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
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...
61
    {
62
        return $this->createFormBuilder()
63
            ->setAction($this->generateUrl('admin_district_delete', array('slug' => $category->getSlug())))
64
            ->setMethod('DELETE')
65
            ->getForm()
66
            ;
67
    }
68
}
69