Code Duplication    Length = 27-28 lines in 3 locations

src/ClientBundle/Controller/CategoryController.php 1 location

@@ 23-50 (lines=28) @@
20
     * @Method({"GET", "POST"})
21
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
22
     */
23
    public function showAction($id, Request $request)
24
    {
25
        $em = $this->getDoctrine()->getManager();
26
        $category = $em->getRepository('ClientBundle:Category')->find($id);
27
28
        if (!$category) {
29
            throw $this->createNotFoundException(sprintf('не знайдений об\'єкт з id : %s', $id));
30
        }
31
32
        $form = $this->createForm(CategoryForm::class, $category);
33
        if ($this->isGranted('ROLE_ADMIN')) {
34
            $form->add('delete', SubmitType::class);
35
        }
36
37
        $form->handleRequest($request);
38
39
        if ($request->isMethod('POST') && $form->isSubmitted() && $form->isValid()) {
40
            $category = $form->getData();
41
            if ($this->isGranted('ROLE_ADMIN') && $form->get('delete')->isClicked()) {
42
                return $this->redirectToRoute('category_del', array('id' => $category->getId()));
43
            }
44
            $em->flush();
45
46
            return $this->redirectToRoute('category_home');
47
        }
48
49
        return $this->render('ClientBundle:Category:edit.html.twig', ['form' => $form->createView(), 'category' => $category]);
50
    }
51
52
    /**
53
     * @return \Symfony\Component\HttpFoundation\Response

src/ClientBundle/Controller/ContactTypeController.php 1 location

@@ 23-49 (lines=27) @@
20
     * @Method({"GET", "POST"})
21
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
22
     */
23
    public function showAction($id, Request $request)
24
    {
25
        $em = $this->getDoctrine()->getManager();
26
        $contactType = $em->getRepository('ClientBundle:ContactType')->find($id);
27
        if (!$contactType) {
28
            throw $this->createNotFoundException(sprintf('не знайдений об\'єкт з id : %s', $id));
29
        } else {
30
            $form = $this->createForm(ContactTypeForm::class, $contactType);
31
            if ($this->isGranted('ROLE_ADMIN')) {
32
                $form->add('delete', SubmitType::class);
33
            }
34
35
            $form->handleRequest($request);
36
37
            if ($request->isMethod('POST') && $form->isSubmitted() && $form->isValid()) {
38
                $contactType = $form->getData();
39
                if ($this->isGranted('ROLE_ADMIN') && $form->get('delete')->isClicked()) {
40
                    return $this->redirectToRoute('contacttype_del', array('id' => $contactType->getId()));
41
                }
42
                $em->flush();
43
44
                return $this->redirectToRoute('contacttype_home');
45
            }
46
47
            return $this->render('ClientBundle:ContactType:edit.html.twig', ['form' => $form->createView(), 'contactType' => $contactType]);
48
        }
49
    }
50
51
    /**
52
     * @Method("GET")

src/ClientBundle/Controller/LangController.php 1 location

@@ 23-49 (lines=27) @@
20
     * @Method({"GET", "POST"})
21
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
22
     */
23
    public function showAction($id, Request $request)
24
    {
25
        $em = $this->getDoctrine()->getManager();
26
        $lang = $em->getRepository('ClientBundle:Lang')->find($id);
27
        if (!$lang) {
28
            throw $this->createNotFoundException(sprintf('не знайдений об\'єкт з id : %s', $id));
29
        } else {
30
            $form = $this->createForm(LangForm::class, $lang);
31
            if ($this->isGranted('ROLE_ADMIN')) {
32
                $form->add('delete', SubmitType::class);
33
            }
34
35
            $form->handleRequest($request);
36
37
            if ($request->isMethod('POST') && $form->isSubmitted() && $form->isValid()) {
38
                $lang = $form->getData();
39
                if ($this->isGranted('ROLE_ADMIN') && $form->get('delete')->isClicked()) {
40
                    return $this->redirectToRoute('lang_del', array('id' => $lang->getId()));
41
                }
42
                $em->flush();
43
44
                return $this->redirectToRoute('lang_home');
45
            }
46
47
            return $this->render('ClientBundle:Lang:edit.html.twig', ['form' => $form->createView(), 'lang' => $lang]);
48
        }
49
    }
50
51
    /**
52
     * @Method("GET")