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

BoletosCliente::gerarBoletos()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
nc 12
nop 2
dl 0
loc 29
rs 8.439
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 BoletosCliente
13
 *
14
 * @author Antonio
15
 */
16
class BoletosCliente extends Nucleo\Instancia {
17
18
    /**
19
     *
20
     * @var \OBRSDK\Entidades\Boletos[]
21
     */
22
    private $boletosParaGerar = [];
23
24
    /**
25
     * Adiciona um boleto para ser gerado
26
     * 
27
     * @param \OBRSDK\Entidades\Boletos $boleto
28
     */
29
    public function addBoletoParaGerar(\OBRSDK\Entidades\Boletos $boleto) {
30
        $this->boletosParaGerar[] = $boleto;
31
    }
32
33
    /**
34
     * Gera os boletos adicionado na lista
35
     * 
36
     * @param \OBRSDK\Entidades\Abstratos\ABanco $banco
37
     * @param \OBRSDK\Entidades\Beneficiario $beneficiario
38
     * @param \OBRSDK\Entidades\Boletos[] $boletos
39
     * @return \OBRSDK\Entidades\Boletos[]
40
     * @throws \OBRSDK\Exceptions\PreenchimentoIncorreto
41
     */
42
    public function gerarBoletos(\OBRSDK\Entidades\Abstratos\ABanco $banco, \OBRSDK\Entidades\Beneficiario $beneficiario) {
43
        $boletos = $this->boletosParaGerar;
44
        $boletos_dados = [];
45
        foreach ($boletos as $boleto) {
46
            $boletos_dados[] = $boleto->getAtributes();
47
        }
48
49
        $response = $this->apiCliente->addAuthorization()
50
                ->postJson('boletos', [
51
                    $banco->getNomeBancoJson() => $banco->getAtributes(),
52
                    "beneficiario" => $beneficiario->getAtributes(),
53
                    "boletos" => $boletos_dados
54
                ])
55
                ->getRespostaArray();
56
57
        $this->boletosParaGerar = [];
58
59
        $quantidadeBoletos = 0;
60
        if (isset($response['boleots'])) {
61
            $quantidadeBoletos = is_array($response['boletos']) ? count($response['boletos']) : 1;
62
        }
63
64
        for ($i = 0; $i < $quantidadeBoletos; $i++) {
65
            // preenche o objeto de boletos recebido
66
            // com as informacoes recebida da api
67
            $boletos[$i]->setAtributos($response['boletos'][$i]);
68
        }
69
70
        return $boletos;
71
    }
72
73
    /**
74
     * 
75
     * @param \OBRSDK\Entidades\Beneficiario $beneficiario
76
     * @param array $query_string_opcional
77
     * @return \OBRSDK\Entidades\Boletos[]
78
     */
79 View Code Duplication
    public function listarBoletos(\OBRSDK\Entidades\Beneficiario $beneficiario, array $query_string_opcional) {
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...
80
        $query_string = array_merge($beneficiario->getAtributes(), $query_string_opcional);
81
82
        $response = $this->apiCliente->addAuthorization()
83
                ->get('boletos', $query_string)
84
                ->getRespostaArray();
85
86
        $boletos = [];
87
        foreach ($response['boletos'] as $boleto) {
88
            $boletoEntidade = new \OBRSDK\Entidades\Boletos();
89
            $boletoEntidade->setAtributos($boleto);
90
            $boletos[] = $boletoEntidade;
91
        }
92
93
        return $boletos;
94
    }
95
96
}
97