Passed
Branch main (02626f)
by Vedrana
05:25
created

LuckyControllerJson::jsonNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
ccs 0
cts 11
cp 0
crap 2
rs 9.9666
1
<?php
2
3
namespace App\Controller;
4
5
use Symfony\Component\HttpFoundation\JsonResponse;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\Routing\Annotation\Route;
8
9
/**
10
 * Controller responsible for returning a lucky number in JSON format.
11
 */
12
class LuckyControllerJson
13
{
14
    /**
15
     * Returns a JSON response containing a random lucky number and a greeting message.
16
     *
17
     * @return Response The JSON response.
18
     */
19
    #[Route("/api/lucky/number")]
20
    public function jsonNumber(): Response
21
    {
22
        $number = random_int(0, 100);
23
24
        $data = [
25
            'lucky-number' => $number,
26
            'lucky-message' => 'Hi there!',
27
        ];
28
29
        $response = new JsonResponse($data);
30
        $response->setEncodingOptions(
31
            $response->getEncodingOptions() | JSON_PRETTY_PRINT
32
        );
33
        return $response;
34
    }
35
}
36