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

PaymentsController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 11.76 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 8
loc 68
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 4 1
A createPaymentGet() 0 4 1
A createPaymentPost() 0 10 1
A searchPayment() 0 7 1
A getPayment() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 PaymentsController
13
 * @package App\Controller\Hyperwallet
14
 *
15
 * @Route("/hyperwallet/payments", name="hyperwallet-payments-")
16
 */
17
class PaymentsController 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/payments/index.html.twig');
27
    }
28
29
    /**
30
     * @Route("/create", name="create-get", methods={"GET"})
31
     *
32
     * @return Response
33
     */
34
    public function createPaymentGet(): Response
35
    {
36
        return $this->render('hyperwallet/payments/create.html.twig');
37
    }
38
39
    /**
40
     * @Route("/create", name="create-post", methods={"POST"})
41
     *
42
     * @return Response
43
     */
44
    public function createPaymentPost(): Response
45
    {
46
        $request = Request::createFromGlobals();
47
        $paymentDetails = $request->request->all();
48
        $payment = $this->hyperwalletService->getPaymentservice()->create($paymentDetails);
49
        return $this->render('default/dump.html.twig', [
50
            'raw_result' => false,
51
            'result' => $payment,
52
        ]);
53
    }
54
55
    /**
56
     * @Route("/search", name="search", methods={"GET"})
57
     *
58
     * @return Response
59
     * @throws HyperwalletApiException
60
     */
61
    public function searchPayment(): Response
62
    {
63
        $payments = $this->hyperwalletService->getPaymentService()->list();
64
        return $this->render('hyperwallet/payments/search.html.twig', [
65
            'payments' => $payments,
66
        ]);
67
    }
68
69
    /**
70
     * @Route("/{paymentToken}", name="get", methods={"GET"})
71
     *
72
     * @param string $paymentToken
73
     *
74
     * @return Response
75
     */
76 View Code Duplication
    public function getPayment(string $paymentToken): 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...
77
    {
78
        $payment = $this->hyperwalletService->getPaymentService()->get($paymentToken);
79
        return $this->render('default/dump.html.twig', [
80
            'raw_result' => false,
81
            'result' => $payment,
82
        ]);
83
    }
84
}
85