Completed
Push — master ( 939420...ce1e21 )
by Adriano
03:21
created

IntencaoVendaApi   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 87
Duplicated Lines 41.38 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 36
loc 87
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getByFiltros() 17 17 3
A getById() 19 19 3

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 Integracao\ControlPay\API;
4
5
use GuzzleHttp\Exception\RequestException;
6
use GuzzleHttp\Message\ResponseInterface;
7
use Integracao\ControlPay\AbstractAPI;
8
use Integracao\ControlPay\Client;
9
use Integracao\ControlPay\Helpers\SerializerHelper;
10
use Integracao\ControlPay\Contracts;
11
12
/**
13
 * Class IntencaoVendaApi
14
 * @package Integracao\ControlPay\API
15
 */
16
class IntencaoVendaApi extends AbstractAPI
17
{
18
19
    /**
20
     * IntencaoVendaApi constructor.
21
     */
22
    public function __construct(Client $client = null)
23
    {
24
        parent::__construct('intencaoVenda', $client);
25
    }
26
27
    /**
28
     * @param Contracts\IntencaoVenda\GetByFiltrosRequest $getByFiltrosRequest
29
     * @return Contracts\IntencaoVenda\GetByFiltrosResponse
30
     * @throws \Exception
31
     */
32 View Code Duplication
    public function getByFiltros(Contracts\IntencaoVenda\GetByFiltrosRequest $getByFiltrosRequest)
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...
33
    {
34
        try{
35
            $this->response = $this->_httpClient->post(__FUNCTION__,[
36
                'body' => json_encode($getByFiltrosRequest),
37
            ]);
38
39
            return SerializerHelper::denormalize(
40
                $this->response->json(),
41
                Contracts\IntencaoVenda\GetByFiltrosResponse::class
42
            );
43
        }catch (RequestException $ex) {
44
            $this->requestException($ex);
45
        }catch (\Exception $ex){
46
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
47
        }
48
    }
49
50
    /**
51
     * @param integer $intencaoVendaId
52
     * @return Contracts\IntencaoVenda\GetByIdResponse
53
     * @throws \Exception
54
     */
55 View Code Duplication
    public function getById($intencaoVendaId)
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...
56
    {
57
        try{
58
            $this->response = $this->_httpClient->post(__FUNCTION__,[
59
                'query' => $this->addQueryAdditionalParameters([
60
                    'intencaoVendaId' => $intencaoVendaId
61
                ])
62
            ]);
63
64
            return SerializerHelper::denormalize(
65
                $this->response->json(),
66
                Contracts\IntencaoVenda\GetByIdResponse::class
67
            );
68
        }catch (RequestException $ex) {
69
            $this->requestException($ex);
70
        }catch (\Exception $ex){
71
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
72
        }
73
    }
74
75
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
//     * API Provavelmente descontinuada
77
//     *
78
//     * @param Contracts\IntencaoVenda\GetByIntegracaoIdRequest $getByIntegracaoIdRequest
79
//     * @return Contracts\IntencaoVenda\GetByIntegracaoIdResponse
80
//     * @throws \Exception
81
//     */
82
//    public function getByIntegracaoId(Contracts\IntencaoVenda\GetByIntegracaoIdRequest $getByIntegracaoIdRequest)
83
//    {
84
//        try{
85
//            $this->response = $this->_httpClient->post(__FUNCTION__,[
86
//                'body' => json_encode($getByIntegracaoIdRequest),
87
//            ]);
88
//
89
//            return SerializerHelper::denormalize(
90
//                $this->response->json(),
91
//                Contracts\IntencaoVenda\GetByIntegracaoIdResponse::class
92
//            );
93
//        }catch (RequestException $ex) {
94
//            $this->response = $ex->getResponse();
95
//            $responseBody = $ex->getResponse()->json();
96
//            throw new \Exception($responseBody['message']);
97
//        }catch (\Exception $ex){
98
//            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
99
//        }
100
//    }
101
102
}