LinkAccountController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 17 2
1
<?php
2
3
/**
4
 * This file is part of the Mediapart LaPresseLibre Bundle.
5
 *
6
 * CC BY-NC-SA <https://github.com/mediapart/lapresselibre-bundle>
7
 *
8
 * For the full license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mediapart\Bundle\LaPresseLibreBundle\Controller;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Response;
16
use Symfony\Component\HttpFoundation\RedirectResponse;
17
use Symfony\Component\HttpKernel\Exception\HttpException;
18
use Mediapart\Bundle\LaPresseLibreBundle\Factory\RedirectionFactory;
19
20
/**
21
 * Use to link an account
22
 */
23
class LinkAccountController
24
{
25
    /**
26
     * @var RedirectionFactory
27
     */
28
    private $redirectionFactory;
29
30
    /**
31
     * @param RedirectionFactory $redirectionFactory
32
     */
33
    public function __construct(RedirectionFactory $redirectionFactory)
34
    {
35
        $this->redirectionFactory = $redirectionFactory;
36
    }
37
38
    /**
39
     * @param Request $request
40
     *
41
     * @return Response
42
     *
43
     * @throws HttpException
44
     */
45
    public function __invoke(Request $request)
46
    {
47
        try {
48
            $redirection = $this
49
                ->redirectionFactory
50
                ->generate($request)
51
            ;
52
            $response = new RedirectResponse($redirection);
53
        } catch (\Exception $exception) {
54
            throw new HttpException(
55
                Response::HTTP_INTERNAL_SERVER_ERROR, 
56
                'Internal Error',
57
                $exception
58
            );
59
        }
60
61
        return $response;
62
    }
63
}
64