PedidoApi::getByPessoaIdByReferencia()   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 20

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
dl 20
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 5
nop 2
1
<?php
2
3
namespace Integracao\ControlPay\API;
4
5
use GuzzleHttp\Exception\RequestException;
6
use Integracao\ControlPay\AbstractAPI;
7
use Integracao\ControlPay\Client;
8
use Integracao\ControlPay\Constants\ControlPayParameterConst;
9
use Integracao\ControlPay\Contracts\Pedido;
10
use Integracao\ControlPay\Helpers\SerializerHelper;
11
12
/**
13
 * Class PedidoApi
14
 * @package Integracao\ControlPay\API
15
 */
16
class PedidoApi extends AbstractAPI
17
{
18
    /**
19
     * PedidoApi constructor.
20
     */
21
    public function __construct(Client $client)
22
    {
23
        parent::__construct('pedido', $client);
24
    }
25
26
    /**
27
     * @param Pedido\InserirRequest $inserirRequest
28
     * @return Pedido\InserirResponse
29
     * @throws \Exception
30
     */
31
    public function insert(Pedido\InserirRequest $inserirRequest)
32
    {
33
        try{
34
35
            foreach ($inserirRequest->getProdutosPedido() as $key => $produto)
0 ignored issues
show
Bug introduced by
The expression $inserirRequest->getProdutosPedido() of type object<Integracao\ControlPay\Model\Produto> is not traversable.
Loading history...
36
            {
37
                if(empty($produto->getId()))
38
                    $inserirRequest->getProdutosPedido()[$key]->setId(
39
                        $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_ID)
40
                    );
41
            }
42
43
            $this->response = $this->_httpClient->post(__FUNCTION__,[
44
                'body' => json_encode($inserirRequest),
45
            ]);
46
47
            return SerializerHelper::denormalize(
48
                $this->response->json(),
49
                Pedido\InserirResponse::class
50
            );
51
        }catch (RequestException $ex) {
52
            $this->requestException($ex);
53
        }catch (\Exception $ex){
54
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
55
        }
56
    }
57
58
    /**
59
     * @param Pedido\GetByFiltrosRequest $getByFiltrosRequest
60
     * @return Pedido\GetByFiltrosResponse
61
     * @throws \Exception
62
     */
63 View Code Duplication
    public function getByFiltros(Pedido\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...
64
    {
65
        try{
66
            $this->response = $this->_httpClient->post(__FUNCTION__,[
67
                'body' => json_encode($getByFiltrosRequest),
68
            ]);
69
70
            return SerializerHelper::denormalize(
71
                $this->response->json(),
72
                Pedido\GetByFiltrosResponse::class
73
            );
74
        }catch (RequestException $ex) {
75
            $this->requestException($ex);
76
        }catch (\Exception $ex){
77
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
78
        }
79
    }
80
81
    /**
82
     * @param $pessoaId
83
     * @param $pedidoReferencia
84
     * @return Pedido\GetByPessoaIdByReferenciaResponse
85
     * @throws \Exception
86
     */
87 View Code Duplication
    public function getByPessoaIdByReferencia($pessoaId, $pedidoReferencia)
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...
88
    {
89
        try{
90
            $this->response = $this->_httpClient->post(__FUNCTION__,[
91
                'query' => $this->addQueryAdditionalParameters([
92
                    'pessoaId' => $pessoaId,
93
                    'pedidoReferencia' => $pedidoReferencia
94
                ])
95
            ]);
96
97
            return SerializerHelper::denormalize(
98
                $this->response->json(),
99
                Pedido\GetByPessoaIdByReferenciaResponse::class
100
            );
101
        }catch (RequestException $ex) {
102
            $this->requestException($ex);
103
        }catch (\Exception $ex){
104
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
105
        }
106
    }
107
108
    /**
109
     * @param $pessoaVendedorId
110
     * @param $pedidoId
111
     * @return Pedido\GetByPessoaIdByReferenciaResponse
112
     * @throws \Exception
113
     */
114 View Code Duplication
    public function getPedidosByPessoaId($pessoaVendedorId, $pedidoId)
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...
115
    {
116
        try{
117
            $this->response = $this->_httpClient->post(__FUNCTION__,[
118
                'query' => $this->addQueryAdditionalParameters([
119
                    'pessoaVendedorId' => $pessoaVendedorId,
120
                    'pedidoId' => $pedidoId
121
                ])
122
            ]);
123
124
            return SerializerHelper::denormalize(
125
                $this->response->json(),
126
                Pedido\GetByPessoaIdByReferenciaResponse::class
127
            );
128
        }catch (RequestException $ex) {
129
            $this->requestException($ex);
130
        }catch (\Exception $ex){
131
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
132
        }
133
    }
134
135
    /**
136
     * @param $pedidoId
137
     * @return Pedido\CancelarResponse
138
     * @throws \Exception
139
     */
140 View Code Duplication
    public function cancelar($pedidoId)
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...
141
    {
142
        try{
143
            $this->response = $this->_httpClient->post(__FUNCTION__,[
144
                'query' => $this->addQueryAdditionalParameters([
145
                    'pedidoId' => $pedidoId
146
                ])
147
            ]);
148
149
            return SerializerHelper::denormalize(
150
                $this->response->json(),
151
                Pedido\CancelarResponse::class
152
            );
153
        }catch (RequestException $ex) {
154
            $this->requestException($ex);
155
        }catch (\Exception $ex){
156
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
157
        }
158
    }
159
160
    /**
161
     * @param integer $pedidoId
162
     * @return Pedido\GetByIdResponse
163
     * @throws \Exception
164
     */
165 View Code Duplication
    public function getById($pedidoId)
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...
166
    {
167
        try{
168
            $this->response = $this->_httpClient->post(__FUNCTION__,[
169
                'query' => $this->addQueryAdditionalParameters([
170
                    'pedidoId' => $pedidoId
171
                ])
172
            ]);
173
174
            return SerializerHelper::denormalize(
175
                $this->response->json(),
176
                Pedido\GetByIdResponse::class
177
            );
178
        }catch (RequestException $ex) {
179
            $this->requestException($ex);
180
        }catch (\Exception $ex){
181
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
182
        }
183
    }
184
}