Completed
Push — master ( 5dadda...07493f )
by Cesar
30s queued 10s
created

AnonymousController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Controller\Paypal;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\Routing\Annotation\Route;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
10
/**
11
 * Class AnonymousController
12
 * @package App\Controller\Paypal
13
 *
14
 * @Route("/paypal/anonymous", name="paypal-anonymous-")
15
 */
16
class AnonymousController extends AbstractController
17
{
18
    /**
19
     * @Route("/", name="index", methods={"GET"})
20
     *
21
     * @return RedirectResponse|Response
22
     */
23
    public function index()
24
    {
25
        if ($this->sessionService->isActive()) {
26
            return $this->redirectToRoute('paypal-authenticated-index');
27
        }
28
        $request = Request::createFromGlobals();
29
        $authToken = $request->get('code');
30
        if ($authToken) {
31
            return $this->render('paypal/anonymous/auth-token.html.twig', [
32
                'auth_token' => $authToken,
33
            ]);
34
        }
35
        return $this->render('paypal/anonymous/index.html.twig', [
36
            'PAYPAL_SDK_CLIENT_ID' =>
37
                $this->sessionService->session->get('PAYPAL_SDK_CLIENT_ID') ??
38
                $this->getParameter('PAYPAL_SDK_CLIENT_ID'),
39
        ]);
40
    }
41
42
    /**
43
     * @Route("/auth-token", name="auth-token", methods={"POST"})
44
     * @return RedirectResponse|Response
45
     */
46 View Code Duplication
    public function anonymousAuthToken()
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...
47
    {
48
        if ($this->sessionService->isActive()) {
49
            return $this->redirectToRoute('paypal-authenticated-index');
50
        }
51
        $request = Request::createFromGlobals();
52
        $authToken = $request->request->get('auth_token', null);
53
        if ($authToken) {
54
            $openIdTokeninfo = $this->paypalService->getIdentityService()->getAccessTokenFromAuthToken($authToken);
55
            if ($openIdTokeninfo) {
56
                return $this->render('paypal/anonymous/access-token.html.twig', [
57
                    'auth_token' => $authToken,
58
                    'access_token' => $openIdTokeninfo->getAccessToken(),
59
                    'refresh_token' => $openIdTokeninfo->getRefreshToken(),
60
                    'accessTokenObject' => $openIdTokeninfo
61
                ]);
62
            }
63
        }
64
        return $this->redirectToRoute('paypal-anonymous-index');
65
    }
66
67
    /**
68
     * @Route("/user-info", name="user-info", methods={"POST"})
69
     * @return RedirectResponse|Response
70
     */
71 View Code Duplication
    public function anonymousUserInfo()
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...
72
    {
73
        if ($this->sessionService->isActive()) {
74
            return $this->redirectToRoute('paypal-authenticated-index');
75
        }
76
        $request = Request::createFromGlobals();
77
        $refreshToken = $request->request->get('refresh_token', null);
78
        if ($refreshToken) {
79
            $userInfo = $this->paypalService->getIdentityService()->getUserInfoFromRefreshToken($refreshToken);
80
            if ($userInfo) {
81
                $this->sessionService->login($userInfo, $refreshToken);
82
                return $this->render('paypal/anonymous/user-info.html.twig', [
83
                    'refresh_token' => $refreshToken,
84
                    'name' => $userInfo->getName(),
85
                    'userInfo' => $userInfo
86
                ]);
87
            }
88
        }
89
        return $this->redirectToRoute('paypal-anonymous-index');
90
    }
91
}
92