QuoteControllerJson   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 25
rs 10
ccs 0
cts 18
cp 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonNumber() 0 23 1
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
class QuoteControllerJson
10
{
11
    #[Route("/api/quote")]
12
    public function jsonNumber(): Response
13
    {
14
        $quoteList = [
15
            "Life is like riding a bicycle. To keep your balance, you must keep moving forward.",
16
            "Its never too late to give up.",
17
            "Theres no such thing as bad weather, only inappropriate clothing."
18
        ];
19
        $randomIndex = random_int(0, count($quoteList) - 1);
20
        $randomQuote = $quoteList[$randomIndex];
21
22
        $data = [
23
            'quote' => $randomQuote,
24
            'date' => date('Y-m-d'),
25
            'timestamp' => date('H:i:s')
26
        ];
27
28
        $response = new JsonResponse($data);
29
        $response->setEncodingOptions(
30
            $response->getEncodingOptions() | JSON_PRETTY_PRINT
31
        );
32
33
        return $response;
34
    }
35
}
36