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 ( 74588a...a37fe1 )
by Christian
07:12
created

AuthController::isAuthenticated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the ni-ju-san CMS.
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\Controller;
13
14
use Core23\LastFm\Service\AuthService;
15
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
19
20
class AuthController extends Controller
21
{
22
    const SESSION_LASTFM_NAME = '_CORE23_LASTFM_NAME';
23
    const SESSION_LASTFM_TOKEN = '_CORE23_LASTFM_TOKEN';
24
25
    /**
26
     * @return Response
27
     */
28
    public function authAction()
29
    {
30
        $callbackUrl = $this->generateUrl('core23_lastfm_check', array(), UrlGeneratorInterface::ABSOLUTE_URL);
31
32
        return $this->redirect($this->getAuthService()->getAuthUrl($callbackUrl));
0 ignored issues
show
Bug introduced by
The method getAuthUrl() does not seem to exist on object<Core23\LastFm\Service\AuthService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
    }
34
35
    /**
36
     * @param Request $request
37
     *
38
     * @return Response
39
     */
40
    public function checkAction(Request $request)
41
    {
42
        $token = $request->query->get('token');
43
44
        if (!$token) {
45
            return $this->redirectToRoute('core23_lastfm_auth');
46
        }
47
48
        // Store session
49
        $lastFmSession = $this->getAuthService()->createSession($token);
50
51
        $session = $this->get('session');
52
        $session->set(static::SESSION_LASTFM_NAME, $lastFmSession->getName());
53
        $session->set(static::SESSION_LASTFM_TOKEN, $lastFmSession->getKey());
54
55
        return $this->redirectToRoute('core23_lastfm_success');
56
    }
57
58
    /**
59
     * @return Response
60
     */
61
    public function errorAction()
62
    {
63
        if ($this->isAuthenticated()) {
64
            return $this->redirectToRoute('core23_lastfm_success');
65
        }
66
67 View Code Duplication
        if (null != $this->getParameter('core23.lastfm.auth_success.redirect_route')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
68
            return $this->redirectToRoute($this->getParameter('core23.lastfm.auth_success.redirect_route'), $this->getParameter('core23.lastfm.auth_success.redirect_route_params'));
69
        }
70
71
        return $this->render('Core23LastFmBundle:Auth:error.html.twig');
72
    }
73
74
    /**
75
     * @return Response
76
     */
77
    public function successAction()
78
    {
79
        if (!$this->isAuthenticated()) {
80
            return $this->redirectToRoute('core23_lastfm_error');
81
        }
82
83 View Code Duplication
        if (null != $this->getParameter('core23.lastfm.auth_success.redirect_route')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
84
            return $this->redirectToRoute($this->getParameter('core23.lastfm.auth_success.redirect_route'), $this->getParameter('core23.lastfm.auth_success.redirect_route_params'));
85
        }
86
87
        $session = $this->get('session');
88
89
        return $this->render('Core23LastFmBundle:Auth:success.html.twig', array(
90
            'name' => $session->get(static::SESSION_LASTFM_NAME),
91
        ));
92
    }
93
94
    /**
95
     * Returns the auth status.
96
     *
97
     * @return bool
98
     */
99
    final protected function isAuthenticated()
100
    {
101
        return (bool) $this->get('session')->get(static::SESSION_LASTFM_TOKEN);
102
    }
103
104
    /**
105
     * @return AuthService
106
     */
107
    private function getAuthService()
108
    {
109
        return $this->get('core23.lastfm.service.auth');
110
    }
111
}
112