OrganizationController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
eloc 20
c 2
b 0
f 2
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 24 3
A __construct() 0 3 1
1
<?php
2
3
namespace App\Controller\Kassabok;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\Routing\Attribute\Route;
11
use App\Entity\Organization;
12
use App\Form\OrganizationFormType;
13
use Symfony\Bundle\SecurityBundle\Security;
14
15
class OrganizationController extends AbstractController
16
{
17
    private $security;
18
19
    public function __construct(Security $security)
20
    {
21
        $this->security = $security;
22
    }
23
24
    #[Route('/proj/organization', name: 'kassabok_organization')]
25
    public function index(Request $request, EntityManagerInterface $entityManager): Response
26
    {
27
        $this->denyAccessUnlessGranted('ROLE_USER');
28
29
        $organization = new Organization();
0 ignored issues
show
Unused Code introduced by
The assignment to $organization is dead and can be removed.
Loading history...
30
        $form = $this->createForm(OrganizationFormType::class);
31
        $form->add('save', SubmitType::class, [
32
            'label' => 'Lägg till',]);
33
        $form->handleRequest($request);
34
35
        if ($form->isSubmitted() && $form->isValid()) {
36
            $organization = $form->getData();
37
            $organization->addUser($this->getUser());
38
39
            $entityManager->persist($organization);
40
            $entityManager->flush();
41
            return $this->redirectToRoute('kassabok_organization');
42
        }
43
44
        return $this->render('kassabok/organization/index.html.twig', [
45
            'controller_name' => 'OrganizationController',
46
            'organizations' => $entityManager->getRepository(Organization::class)->findByUser($this->getUser()),
47
            'form' => $form,
48
        ]);
49
    }
50
51
    // public function new(Request $request): Response
52
    // {
53
    //     $this->denyAccessUnlessGranted('ROLE_USER');
54
55
    //     $organization = new Organization();
56
57
    //     $form = $this->createForm(OrganizationFormType::class);
58
    //     $form->handleRequest($request);
59
60
    //     if ($form->isSubmitted() && $form->isValid()) {
61
    //         $organization = $form->getData();
62
63
    //         return $this->redirectToRoute('kassabok_organization');
64
    //     }
65
    // }
66
}
67