Completed
Pull Request — master (#30)
by nonanerz
05:40
created

AdminController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 21 3
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Entity\Admin;
6
use AppBundle\Form\AdminType;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
12
13
/**
14
 * Class DefaultController.
15
 *
16
 * @Route("/admin", name="admin")
17
 */
18
class AdminController extends Controller
19
{
20
    /**
21
     * @Route("/", name="admin_info")
22
     * @Template("@App/Admin/index.html.twig")
23
     *
24
     * @param Request $request
25
     *
26
     * @return array
27
     */
28 1
    public function indexAction(Request $request)
29
    {
30 1
        $em = $this->getDoctrine()->getManager();
31 1
        $admin = $em->getRepository(Admin::class)->findOneBy(['id' => $this->getUser()->getId()]);
32 1
        $editForm = $this->createForm(AdminType::class, $admin)
33 1
            ->add('Save', SubmitType::class, array(
34 1
                'attr' => array('class' => 'btn btn-primary'),
35
            ));
36 1
        $editForm->handleRequest($request);
37 1
        if ($editForm->isSubmitted()) {
38 1
            if ($editForm->isValid()) {
39 1
                $em->persist($admin);
40 1
                $em->flush();
41
            }
42
        }
43
44
        return [
45 1
            'admin' => $admin,
46 1
            'editForm' => $editForm->createView(),
47
        ];
48
    }
49
}
50