Passed
Push — master ( c4fb31...6466f2 )
by Antônio
01:43
created

RemessasCliente::organizarDadosRemessa()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 1
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace OBRSDK\HttpClient;
10
11
/**
12
 * Description of RemessasCliente
13
 *
14
 * @author Antonio
15
 */
16
class RemessasCliente extends Nucleo\Instancia {
17
18
    /**
19
     * 
20
     * @param \OBRSDK\Entidades\Remessas $remessas
21
     * @return \OBRSDK\Entidades\Remessas[]
22
     */
23 View Code Duplication
    public function gerarRemessa(\OBRSDK\Entidades\Remessas $remessas) {
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...
24
        $remessas_dados = $this->organizarDadosRemessa($remessas->getAtributes());
25
26
        $resposta = $this->apiCliente->addAuthorization()
27
                ->postJson('remessas', $remessas_dados)
28
                ->getRespostaArray();
29
30
        $remessasResponse = [];
31
        // preenche com objeto de resposta
32
        foreach ($resposta['remessas'] as $remessa) {
33
            $remessaEntidade = new \OBRSDK\Entidades\Remessas();
34
            $remessaEntidade->setAtributos($remessa);
35
            $remessasResponse[] = $remessaEntidade;
36
        }
37
38
        return $remessasResponse;
39
    }
40
41
    /**
42
     * @param string $remessa_id
43
     * @return \OBRSDK\Entidades\Remessas
44
     */
45
    public function getRemessaPorId($remessa_id) {
46
        $resposta = $this->apiCliente->addAuthorization()
47
                        ->get('remessas/' . $remessa_id)->getRespostaArray();
48
49
        $remessa_resposta = new \OBRSDK\Entidades\Remessas();
50
        $remessa_resposta->setAtributos($resposta);
51
52
        return $remessa_resposta;
53
    }
54
55
    /**
56
     * 
57
     * @param array $remessas_dados
58
     * @return array
59
     */
60
    private function organizarDadosRemessa(array $remessas_dados) {
61
        if (!isset($remessas_dados['boletos']) || !is_array($remessas_dados['boletos'])) {
62
            $remessas_dados['boletos'] = [];
63
        }
64
65
        $boletos = [];
66
        foreach ($remessas_dados['boletos'] as $boleto) {
67
            $boletos[] = [
68
                "boleto_id" => $boleto['boleto_id']
69
            ];
70
        }
71
        // remove dados anterior
72
        unset($remessas_dados['boletos']);
73
        // seta com dados atualizado
74
        $remessas_dados['boletos'] = $boletos;
75
76
        return $remessas_dados;
77
    }
78
79
}
80