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.

AuthErrorAction::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
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\LastFmBundle\Action;
13
14
use Core23\LastFmBundle\Core23LastFmEvents;
15
use Core23\LastFmBundle\Event\AuthFailedEvent;
16
use Core23\LastFmBundle\Session\SessionManagerInterface;
17
use Symfony\Component\HttpFoundation\RedirectResponse;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
20
use Symfony\Component\Routing\RouterInterface;
21
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
22
use Twig\Environment;
23
use Twig\Error\LoaderError;
24
use Twig\Error\RuntimeError;
25
use Twig\Error\SyntaxError;
26
27
final class AuthErrorAction
28
{
29
    /**
30
     * @var Environment
31
     */
32
    private $twig;
33
34
    /**
35
     * @var RouterInterface
36
     */
37
    private $router;
38
39
    /**
40
     * @var SessionManagerInterface
41
     */
42
    private $sessionManager;
43
44
    /**
45
     * @var EventDispatcherInterface
46
     */
47
    private $eventDispatcher;
48
49 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
        Environment $twig,
51
        RouterInterface $router,
52
        SessionManagerInterface $sessionManager,
53
        EventDispatcherInterface $eventDispatcher
54
    ) {
55
        $this->twig            = $twig;
56
        $this->router          = $router;
57
        $this->sessionManager  = $sessionManager;
58
        $this->eventDispatcher = $eventDispatcher;
59
    }
60
61
    /**
62
     * @throws LoaderError
63
     * @throws RuntimeError
64
     * @throws SyntaxError
65
     */
66
    public function __invoke(): Response
67
    {
68
        if ($this->sessionManager->isAuthenticated()) {
69
            return new RedirectResponse($this->generateUrl('core23_lastfm_success'));
70
        }
71
72
        $this->sessionManager->clear();
73
74
        $event = new AuthFailedEvent();
75
        $this->eventDispatcher->dispatch($event, Core23LastFmEvents::AUTH_ERROR);
76
77
        if (null !== $response = $event->getResponse()) {
78
            return $response;
79
        }
80
81
        return new Response($this->twig->render('@Core23LastFm/Auth/error.html.twig'));
82
    }
83
84
    /**
85
     * Generates a URL from the given parameters.
86
     *
87
     * @param string $route         The name of the route
88
     * @param array  $parameters    An array of parameters
89
     * @param int    $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
90
     *
91
     * @return string The generated URL
92
     */
93
    private function generateUrl(string $route, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string
94
    {
95
        return $this->router->generate($route, $parameters, $referenceType);
96
    }
97
}
98