Completed
Push — master ( 007a99...a68933 )
by methylbro
13s
created

LinkAccountController::__invoke()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 1
nop 1
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
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