Conditions | 1 |
Paths | 1 |
Total Lines | 28 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 18 |
CRAP Score | 1 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | 1 | #[Route("/api/quote")] |
|
20 | public function jsonQuote(): Response |
||
21 | { |
||
22 | 1 | $quotes = [ |
|
23 | 1 | "An old silent pond - A frog jumps into the pond - Splash! Silence again.", |
|
24 | 1 | "A world of dew - And within every dewdrop - A world of struggle.", |
|
25 | 1 | "The apparition of these faces in the crowd - Petals on a wet, black bough.", |
|
26 | 1 | "I write, erase, rewrite - Erase again, and then - A poppy blooms." |
|
27 | 1 | ]; |
|
28 | |||
29 | // Choose a random quote from the list |
||
30 | 1 | $randomQuote = $quotes[array_rand($quotes)]; |
|
31 | |||
32 | 1 | $data = [ |
|
33 | 1 | 'quote' => $randomQuote, |
|
34 | 1 | 'date' => date('Y-m-d'), |
|
35 | 1 | 'timestamp' => date('Y-m-d H:i:s') |
|
36 | 1 | ]; |
|
37 | |||
38 | // Create a JSON response with the quote, today's date, and timestamp |
||
39 | 1 | $response = new JsonResponse($data); |
|
40 | |||
41 | // Optionally, set JSON_PRETTY_PRINT flag for pretty formatting |
||
42 | 1 | $response->setEncodingOptions( |
|
43 | 1 | $response->getEncodingOptions() | JSON_PRETTY_PRINT |
|
44 | 1 | ); |
|
45 | |||
46 | 1 | return $response; |
|
47 | } |
||
49 |