SessionController::session()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
ccs 0
cts 5
cp 0
crap 2
1
<?php
2
3
namespace App\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpFoundation\Session\SessionInterface;
9
use Symfony\Component\Routing\Annotation\Route;
10
11
class SessionController extends AbstractController
12
{
13
    #[Route('/session', name: "session_index")]
14
    public function session(
15
        SessionInterface $session
16
    ): Response {
17
        $data = [
18
            'session' => $session->all()
19
        ];
20
21
        return $this->render('session/index.html.twig', $data);
22
    }
23
24
    #[Route("/api/session", name: "session_api")]
25
    public function sessionJson(
26
        SessionInterface $session
27
    ): Response {
28
        $data = [
29
            'session' => $session->all()
30
        ];
31
32
        $response = new JsonResponse($data);
33
        $response->setEncodingOptions(
34
            $response->getEncodingOptions() | JSON_PRETTY_PRINT
35
        );
36
        return $response;
37
    }
38
39
    #[Route("/session/clear", name: "session_clear")]
40
    public function clearSession(
41
        SessionInterface $session
42
    ): Response {
43
        $session->clear();
44
45
        return $this->redirectToRoute('session_index');
46
    }
47
}
48