QuoteControllerJson::jsonNumber()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 23
rs 9.7666
ccs 0
cts 18
cp 0
crap 2
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