IndexController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 29
ccs 0
cts 17
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A index() 0 20 4
1
<?php
2
3
namespace App\Controller;
4
5
# Generic use statements
6
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Routing\Attribute\Route;
9
10
# Specific use statements
11
use App\Service\QuoteService;
12
13
class IndexController extends AbstractController
14
{
15
    protected QuoteService $quoteService;
16
17
    public function __construct(QuoteService $quoteService)
18
    {
19
        $this->quoteService = $quoteService;
20
    }
21
22
    #[Route('/', name: 'app_home')]
23
    public function index(): Response
24
    {
25
        $json = $this->quoteService->getAssadsQuote()->getContent();
26
        if ($json === false || $json === null || $json === '') {
0 ignored issues
show
introduced by
The condition $json === null is always false.
Loading history...
27
            return new Response('Failed to get quote data.');
28
        }
29
        $quote = json_decode(
30
            $json,
31
            true
32
        );
33
34
        $data = [
35
            'quoteData' => [
36
                'quote' => $quote['quote'],
37
                'explanation' => $quote['explanation']
38
            ]
39
        ];
40
41
        return $this->render('index.html.twig', $data);
42
    }
43
}
44