ExchangeRatesController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A calculator() 0 16 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace App\Controller;
6
7
use App\Entity\ExchangeEnquiry;
8
use App\ExchangeRates\ExchangeService;
9
use App\Form\Type\ExchangeEnquiryType;
10
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\Routing\Annotation\Route;
14
15
class ExchangeRatesController extends AbstractController
16
{
17
    /**
18
     * @Route("/", name="main_page")
19
     *
20
     * @param Request         $request
21
     * @param ExchangeService $service
22
     *
23
     * @return Response
24
     */
25
    public function calculator(Request $request, ExchangeService $service): Response
26
    {
27
        $exchangeEnquiry = new ExchangeEnquiry();
28
        $form            = $this->createForm(ExchangeEnquiryType::class, $exchangeEnquiry);
29
30
        $form->handleRequest($request);
31
32
        if ($form->isSubmitted() && $form->isValid()) {
33
            return $this->render('result.html.twig', [
34
                'enquiry' => $exchangeEnquiry,
35
                'result'  => $service->exchange($exchangeEnquiry),
36
            ]);
37
        }
38
39
        return $this->render('calculator.html.twig', [
40
            'form' => $form->createView(),
41
        ]);
42
    }
43
}
44