Completed
Push — master ( 79428d...367fd6 )
by Cesar
27s queued 11s
created

UsersController::readUser()   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 View Code Duplication
    public function createUserPost(): 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...
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