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