Completed
Push — master ( dc1ac5...ac28ba )
by Adriano
07:48
created

IntencaoVendaApi::getByFiltrosAsync()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 13
nc 5
nop 1
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
    public function getByFiltros(Contracts\IntencaoVenda\GetByFiltrosRequest $getByFiltrosRequest)
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->response = $ex->getResponse();
45
            $responseBody = $ex->getResponse()->json();
46
            throw new \Exception($responseBody['message']);
47
        }catch (\Exception $ex){
48
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
49
        }
50
    }
51
52
    /**
53
     * @param Contracts\IntencaoVenda\GetByFiltrosRequest $getByFiltrosRequest
54
     * @return Contracts\IntencaoVenda\GetByFiltrosResponse
55
     * @throws \Exception
56
     */
57
    public function getByFiltrosAsync(Contracts\IntencaoVenda\GetByFiltrosRequest $getByFiltrosRequest)
58
    {
59
        try{
60
            $this->response = $this->_httpClient->post(__FUNCTION__,[
61
                'body' => json_encode($getByFiltrosRequest),
62
            ]);
63
64
            return SerializerHelper::denormalize(
65
                $this->response->json(),
66
                Contracts\IntencaoVenda\GetByFiltrosResponse::class
67
            );
68
        }catch (RequestException $ex) {
69
            $this->response = $ex->getResponse();
70
            $responseBody = $ex->getResponse()->json();
71
            throw new \Exception($responseBody['message']);
72
        }catch (\Exception $ex){
73
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
74
        }
75
    }
76
77
    /**
78
     * @param integer $intencaoVendaId
79
     * @return Contracts\IntencaoVenda\GetByIdResponse
80
     * @throws \Exception
81
     */
82 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...
83
    {
84
        try{
85
            $this->response = $this->_httpClient->post(__FUNCTION__,[
86
                'query' => $this->addQueryAdditionalParameters([
87
                    'intencaoVendaId' => $intencaoVendaId
88
                ])
89
            ]);
90
91
            return SerializerHelper::denormalize(
92
                $this->response->json(),
93
                Contracts\IntencaoVenda\GetByIdResponse::class
94
            );
95
        }catch (RequestException $ex) {
96
            $this->response = $ex->getResponse();
97
            $responseBody = $ex->getResponse()->json();
98
            throw new \Exception($responseBody['message']);
99
        }catch (\Exception $ex){
100
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
101
        }
102
    }
103
104
//    /**
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...
105
//     * API Provavelmente descontinuada
106
//     *
107
//     * @param Contracts\IntencaoVenda\GetByIntegracaoIdRequest $getByIntegracaoIdRequest
108
//     * @return Contracts\IntencaoVenda\GetByIntegracaoIdResponse
109
//     * @throws \Exception
110
//     */
111
//    public function getByIntegracaoId(Contracts\IntencaoVenda\GetByIntegracaoIdRequest $getByIntegracaoIdRequest)
112
//    {
113
//        try{
114
//            $this->response = $this->_httpClient->post(__FUNCTION__,[
115
//                'body' => json_encode($getByIntegracaoIdRequest),
116
//            ]);
117
//
118
//            return SerializerHelper::denormalize(
119
//                $this->response->json(),
120
//                Contracts\IntencaoVenda\GetByIntegracaoIdResponse::class
121
//            );
122
//        }catch (RequestException $ex) {
123
//            $this->response = $ex->getResponse();
124
//            $responseBody = $ex->getResponse()->json();
125
//            throw new \Exception($responseBody['message']);
126
//        }catch (\Exception $ex){
127
//            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
128
//        }
129
//    }
130
131
}