Passed
Push — master ( d0defb...6219a1 )
by
unknown
07:54
created

TestApiKeysAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __invoke() 0 13 2
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\Controller\Action\Admin;
13
14
use BitBag\SyliusMolliePlugin\Resolver\ApiKeysTestResolverInterface;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use Twig\Environment;
18
19
final class TestApiKeysAction
20
{
21
    /** @var ApiKeysTestResolverInterface */
22
    private $apiKeysTestResolver;
23
24
    /** @var Environment */
25
    private $twig;
26
27
    public function __construct(
28
        ApiKeysTestResolverInterface $apiKeysTestResolver,
29
        Environment $twig
30
    ) {
31
        $this->apiKeysTestResolver = $apiKeysTestResolver;
32
        $this->twig = $twig;
33
    }
34
35
    public function __invoke(Request $request): Response
36
    {
37
        try {
38
            $data = $this->apiKeysTestResolver->fromRequest($request);
39
40
            return new Response($this->twig->render(
41
                '@BitBagSyliusMolliePlugin/Admin/PaymentMethod/testApiKeys.html.twig',
42
                [
43
                    'tests' => $data,
44
                ]
45
            ));
46
        } catch (\Exception $exception) {
47
            return new Response($exception->getMessage(), Response::HTTP_BAD_REQUEST);
48
        }
49
    }
50
}
51