Completed
Pull Request — dev (#27)
by
unknown
03:07
created

AdminController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 17 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
12
/**
13
 * Class DefaultController
14
 * @Route("/admin", name="admin")
15
 * @package AppBundle\Controller
16
 */
17
class AdminController extends Controller
18
{
19
    /**
20
     * @Route("/", name="admin_info")
21
     * @Template("@App/Admin/index.html.twig")
22
     *
23
     * @param Request $request
24
     * @return array
25
     */
26 1
    public function indexAction(Request $request)
27
    {
28 1
        $em = $this->getDoctrine()->getManager();
29 1
        $admin = $em->getRepository(Admin::class)->findOneBy(['id' => $this->getUser()->getId()]);
30 1
        $editForm = $this->createForm(AdminType::class, $admin);
31 1
        $editForm->handleRequest($request);
32 1
        if ($editForm->isSubmitted()) {
33 1
            if ($editForm->isValid()) {
34 1
                $em->persist($admin);
35 1
                $em->flush();
36
            }
37
        }
38
        return [
39 1
            "admin" => $admin,
40 1
            "editForm" => $editForm->createView(),
41
        ];
42
    }
43
}
44