GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( cc1a00...2cee89 )
by Christian
15:25
created

AuthSuccessAction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 100
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A __invoke() 0 14 3
A redirectToRoute() 0 4 1
A generateUrl() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\FacebookBundle\Action;
13
14
use Core23\FacebookBundle\Session\SessionManager;
15
use Symfony\Component\HttpFoundation\RedirectResponse;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
18
use Symfony\Component\Routing\RouterInterface;
19
use Twig\Environment;
20
21
final class AuthSuccessAction
22
{
23
    /**
24
     * @var Environment
25
     */
26
    private $twig;
27
28
    /**
29
     * @var RouterInterface
30
     */
31
    private $router;
32
33
    /**
34
     * @var SessionManager
35
     */
36
    private $sessionManager;
37
38
    /**
39
     * @var string|null
40
     */
41
    private $redirectRoute;
42
43
    /**
44
     * @var array
45
     */
46
    private $redirectRouteParams;
47
48
    /**
49
     * AuthSuccessAction constructor.
50
     *
51
     * @param Environment     $twig
52
     * @param RouterInterface $router
53
     * @param SessionManager  $sessionManager
54
     * @param null|string     $redirectRoute
55
     * @param array           $redirectRouteParams
56
     */
57
    public function __construct(
58
        Environment $twig,
59
        RouterInterface $router,
60
        SessionManager $sessionManager,
61
        ?string $redirectRoute,
62
        array $redirectRouteParams
63
    ) {
64
        $this->twig                = $twig;
65
        $this->router              = $router;
66
        $this->sessionManager      = $sessionManager;
67
        $this->redirectRoute       = $redirectRoute;
68
        $this->redirectRouteParams = $redirectRouteParams;
69
    }
70
71
    /**
72
     * @throws \Twig_Error_Loader
73
     * @throws \Twig_Error_Runtime
74
     * @throws \Twig_Error_Syntax
75
     *
76
     * @return Response
77
     */
78
    public function __invoke(): Response
79
    {
80
        if (!$this->sessionManager->isAuthenticated()) {
81
            return $this->redirectToRoute('core23_facebook_error');
82
        }
83
84
        if (null !== $this->redirectRoute) {
85
            return $this->redirectToRoute($this->redirectRoute, $this->redirectRouteParams);
86
        }
87
88
        return new Response($this->twig->render('@Core23Facebook/Auth/success.html.twig', [
89
            'name' => $this->sessionManager->getUsername(),
90
        ]));
91
    }
92
93
    /**
94
     * Returns a RedirectResponse to the given route with the given parameters.
95
     *
96
     * @param string $route      The name of the route
97
     * @param array  $parameters An array of parameters
98
     * @param int    $status     The status code to use for the Response
99
     *
100
     * @return RedirectResponse
101
     */
102
    private function redirectToRoute($route, array $parameters = [], $status = 302): RedirectResponse
103
    {
104
        return new RedirectResponse($this->generateUrl($route, $parameters), $status);
105
    }
106
107
    /**
108
     * Generates a URL from the given parameters.
109
     *
110
     * @param string $route         The name of the route
111
     * @param array  $parameters    An array of parameters
112
     * @param int    $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
113
     *
114
     * @return string The generated URL
115
     */
116
    private function generateUrl($route, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string
117
    {
118
        return $this->router->generate($route, $parameters, $referenceType);
119
    }
120
}
121