Completed
Push — master ( 93b855...faa581 )
by Cesar
21s queued 10s
created

UsersController::getAuthenticationToken()   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 1
1
<?php
2
3
namespace App\Controller\Hyperwallet;
4
5
use Hyperwallet\Exception\HyperwalletApiException;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\Routing\Annotation\Route;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Class UsersController
13
 * @package App\Controller\Paypal
14
 *
15
 * @Route("/hyperwallet/users", name="hyperwallet-users-")
16
 */
17
class UsersController extends AbstractController
18
{
19
    /**
20
     * @Route("/", name="index", methods={"GET"})
21
     *
22
     * @return Response
23
     */
24
    public function index(): Response
25
    {
26
        return $this->render('hyperwallet/users/index.html.twig');
27
    }
28
29
    /**
30
     * @Route("/create", name="create-get", methods={"GET"})
31
     *
32
     * @return Response
33
     */
34
    public function createUserGet(): Response
35
    {
36
        return $this->render('hyperwallet/users/create.html.twig');
37
    }
38
39
    /**
40
     * @Route("/create", name="create-post", methods={"POST"})
41
     *
42
     * @return Response
43
     */
44
    public function createUserPost(): Response
45
    {
46
        $request = Request::createFromGlobals();
47
        $userData = $request->request->all();
48
        $user = $this->hyperwalletService->getUserService()->create($userData);
49
        return $this->render('default/dump.html.twig', [
50
            'raw_result' => false,
51
            'result' => $user,
52
        ]);
53
    }
54
55
    /**
56
     * @Route("/search", name="search", methods={"GET"})
57
     *
58
     * @return Response
59
     * @throws HyperwalletApiException
60
     */
61
    public function searchUser(): Response
62
    {
63
        $users = $this->hyperwalletService->getUserService()->list();
64
        return $this->render('hyperwallet/users/search.html.twig', [
65
            'users' => $users,
66
        ]);
67
    }
68
69
    /**
70
     * @Route("/get/{userToken}", name="read", methods={"GET"})
71
     *
72
     * @param string $userToken
73
     *
74
     * @return JsonResponse
75
     */
76
    public function readUser(string $userToken): JsonResponse
77
    {
78
        $user = $this->hyperwalletService->getUserService()->get($userToken);
79
        return new JsonResponse($user->getProperties());
0 ignored issues
show
Bug introduced by
The method getProperties does only exist in Hyperwallet\Model\User, but not in Exception.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
80
    }
81
82
    /**
83
     * @Route("/edit/{userToken}", name="edit-get", methods={"GET"})
84
     *
85
     * @param string $userToken
86
     *
87
     * @return Response
88
     */
89
    public function editUserGet(string $userToken): Response
90
    {
91
        $userJson = $this->hyperwalletService->getUserService()->get($userToken)->getProperties();
0 ignored issues
show
Bug introduced by
The method getProperties does only exist in Hyperwallet\Model\User, but not in Exception.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
92
        return $this->render('hyperwallet/users/edit.html.twig', [
93
            'userJson' => json_encode($userJson)
94
        ]);
95
    }
96
97
    /**
98
     * @Route("/edit", name="edit-post", methods={"POST"})
99
     *
100
     * @return Response
101
     */
102
    public function editUserPost(): Response
103
    {
104
        $request = Request::createFromGlobals();
105
        $userData = $request->request->all();
106
        $user = $this->hyperwalletService->getUserService()->update($userData);
107
        return $this->render('default/dump.html.twig', [
108
            'raw_result' => false,
109
            'result' => $user,
110
        ]);
111
    }
112
113
    /**
114
     * @Route("/{userToken}/transfer-methods", name="transfer-methods-list", methods={"GET"})
115
     *
116
     * @param string $userToken
117
     *
118
     * @return Response
119
     */
120 View Code Duplication
    public function transferMethodsList(string $userToken): Response
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...
121
    {
122
        $transferMethods = $this->hyperwalletService->getUserService()->listTransferMethods($userToken);
123
        return $this->render('default/dump.html.twig', [
124
            'raw_result' => false,
125
            'result' => $transferMethods,
126
        ]);
127
    }
128
129
    /**
130
     * @Route("/{userToken}/balance", name="balance", methods={"GET"})
131
     *
132
     * @param string $userToken
133
     *
134
     * @return Response
135
     */
136 View Code Duplication
    public function balanceList(string $userToken): Response
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...
137
    {
138
        $balance = $this->hyperwalletService->getUserService()->listBalances($userToken);
139
        return $this->render('default/dump.html.twig', [
140
            'raw_result' => false,
141
            'result' => $balance,
142
        ]);
143
    }
144
145
    /**
146
     * @Route("/{userToken}/transfer-methods/add", name="transfer-methods-add", methods={"GET"})
147
     *
148
     * @param string $userToken
149
     *
150
     * @return Response
151
     */
152 View Code Duplication
    public function transferMethodAdd(string $userToken): Response
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...
153
    {
154
        $userJson = $this->hyperwalletService->getUserService()->get($userToken)->getProperties();
0 ignored issues
show
Bug introduced by
The method getProperties does only exist in Hyperwallet\Model\User, but not in Exception.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
155
        return $this->render('hyperwallet/users/transferMethods/create.html.twig', [
156
            'userJson' => $userJson
157
        ]);
158
    }
159
160
    /**
161
     * @Route("/{userToken}/verify", name="verify", methods={"GET"})
162
     *
163
     * @param string $userToken
164
     *
165
     * @return Response
166
     */
167 View Code Duplication
    public function verify(string $userToken): Response
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...
168
    {
169
        $userJson = $this->hyperwalletService->getUserService()->get($userToken)->getProperties();
0 ignored issues
show
Bug introduced by
The method getProperties does only exist in Hyperwallet\Model\User, but not in Exception.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
170
        return $this->render('hyperwallet/users/verify.html.twig', [
171
            'userJson' => $userJson
172
        ]);
173
    }
174
175
    /**
176
     * @Route("/{userToken}/authentication-token", name="auth-token", methods={"GET"})
177
     *
178
     * @param string $userToken
179
     *
180
     * @return JsonResponse
181
     */
182
    public function getAuthenticationToken(string $userToken): JsonResponse
183
    {
184
        $authenticationToken = $this->hyperwalletService->getUserService()->getAuthenticationToken($userToken);
185
        return new JsonResponse($authenticationToken->getValue());
0 ignored issues
show
Bug introduced by
The method getValue does only exist in Hyperwallet\Model\AuthenticationToken, but not in Exception.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
186
    }
187
188
    /**
189
     * @Route("/{userToken}/transfer-create", name="transfer-create", methods={"GET"})
190
     *
191
     * @param string $userToken
192
     *
193
     * @return Response
194
     */
195
    public function transferCreate(string $userToken): Response
196
    {
197
        $balance = $this->hyperwalletService->getUserService()->listBalances($userToken);
198
        $transferMethods = $this->hyperwalletService->getUserService()->listTransferMethods($userToken);
199
        return $this->render('hyperwallet/users/transfer.html.twig', [
200
            'balance' => $balance,
201
            'transferMethods' => $transferMethods,
202
            'userToken' => $userToken,
203
        ]);
204
    }
205
}
206