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

AuthErrorAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 5
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 AuthErrorAction
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
     * AuthErrorAction 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_success');
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/error.html.twig'));
89
    }
90
91
    /**
92
     * Returns a RedirectResponse to the given route with the given parameters.
93
     *
94
     * @param string $route      The name of the route
95
     * @param array  $parameters An array of parameters
96
     * @param int    $status     The status code to use for the Response
97
     *
98
     * @return RedirectResponse
99
     */
100
    private function redirectToRoute($route, array $parameters = [], $status = 302): RedirectResponse
101
    {
102
        return new RedirectResponse($this->generateUrl($route, $parameters), $status);
103
    }
104
105
    /**
106
     * Generates a URL from the given parameters.
107
     *
108
     * @param string $route         The name of the route
109
     * @param array  $parameters    An array of parameters
110
     * @param int    $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
111
     *
112
     * @return string The generated URL
113
     */
114
    private function generateUrl($route, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string
115
    {
116
        return $this->router->generate($route, $parameters, $referenceType);
117
    }
118
}
119