IndexController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 1
dl 0
loc 3
c 0
b 0
f 0
cc 1
ccs 0
cts 2
cp 0
crap 2
rs 10
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