Kmom03Json   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 21
rs 10
ccs 0
cts 11
cp 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A game() 0 19 1
1
<?php
2
3
namespace App\Controller;
4
5
use App\Game\Game;
6
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\HttpFoundation\Session\SessionInterface;
11
use Symfony\Component\Routing\Annotation\Route;
12
use Symfony\Component\Routing\RouterInterface;
13
14
class Kmom03Json extends AbstractController
15
{
16
    #[Route("/api/game", name: 'json-game', methods: ['GET'], defaults: ['description' => 'Returnerar en JSON-struktur med den aktuella ställningen för spelet.'])]
17
    public function game(
18
        SessionInterface $session
19
    ): Response {
20
        // Hämta spelomgång från session
21
        /** @var Game $game */
22
        $game = $session->get('game');
23
24
        // Returnerar aktuell ställning som JSON-struktur
25
        $data = [
26
            "playerScore" => $game->getPlayerScore(),
27
            "bankScore" => $game->getBankScore()
28
        ];
29
30
        $response = new JsonResponse($data);
31
        $response->setEncodingOptions(
32
            $response->getEncodingOptions() | JSON_PRETTY_PRINT
33
        );
34
        return $response;
35
    }
36
}
37