LuckyController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 35
rs 10
ccs 0
cts 22
cp 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonQuote() 0 21 1
A lucky() 0 10 1
1
<?php
2
3
namespace App\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\Routing\Annotation\Route;
9
10
class LuckyController extends AbstractController
11
{
12
    #[Route("/lucky", name: "lucky")]
13
    public function lucky(): Response
14
    {
15
        $number = random_int(0, 100);
16
17
        $data = [
18
            'number' => $number
19
        ];
20
21
        return $this->render('lucky.html.twig', $data);
22
    }
23
24
    #[Route("/api/quote", name: "quote")]
25
    public function jsonQuote(): JsonResponse
26
    {
27
        $quotes = [
28
            0 => "The early bird might get the worm, but the late bird gets to sleep in and have pancakes for breakfast.",
29
            1 => "I have always said that the key to happiness is a good pair of fuzzy socks and a tub of ice cream.",
30
            2 => "Always remember, when in doubt, hug a tree and it will give you the answer to any question you may have."
31
        ];
32
33
        $randKey = array_rand($quotes, 1);
34
35
        $data = [
36
            'quote' => $quotes[$randKey],
37
            'date' => date('l jS \of F Y G:i:s'),
38
        ];
39
40
        $response = new JsonResponse($data);
41
        $response->setEncodingOptions(
42
            $response->getEncodingOptions() | JSON_PRETTY_PRINT
43
        );
44
        return $response;
45
    }
46
}
47