Passed
Push — main ( a57e19...f52e71 )
by Vedrana
28:10
created

LuckyControllerJson::jsonNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

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 11
cts 11
cp 1
crap 1
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 1
    #[Route("/api/lucky/number")]
20
    public function jsonNumber(): Response
21
    {
22 1
        $number = random_int(0, 100);
23
24 1
        $data = [
25 1
            'lucky-number' => $number,
26 1
            'lucky-message' => 'Hi there!',
27 1
        ];
28
29 1
        $response = new JsonResponse($data);
30 1
        $response->setEncodingOptions(
31 1
            $response->getEncodingOptions() | JSON_PRETTY_PRINT
32 1
        );
33 1
        return $response;
34
    }
35
}
36