Passed
Push — master ( 6466f2...326f15 )
by Antônio
01:59
created

BoletosCliente::getBodyGerarBoletos()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 10
rs 9.4285
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
        $resposta = $this->apiCliente->addAuthorization()
44
                ->postJson('boletos', $this->getBodyGerarBoletos($banco, $beneficiario))
45
                ->getRespostaArray();
46
47
        $quantidadeBoletos = !isset($resposta['boletos']) ? 0 : count($resposta['boletos']);
48
49
        $boletos = $this->boletosParaGerar;
50
        for ($i = 0; $i < $quantidadeBoletos; $i++) {
51
            $boletos[$i]->setAtributos($resposta['boletos'][$i]);
52
        }
53
        $this->boletosParaGerar = [];
54
55
        return $boletos;
56
    }
57
58
    /**
59
     * 
60
     * @param \OBRSDK\Entidades\Beneficiario $beneficiario
61
     * @param array $query_string_opcional
62
     * @return \OBRSDK\Entidades\Boletos[]
63
     */
64 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...
65
        $query_string = array_merge($beneficiario->getAtributes(), $query_string_opcional);
66
67
        $response = $this->apiCliente->addAuthorization()
68
                ->get('boletos', $query_string)
69
                ->getRespostaArray();
70
71
        $boletos = [];
72
        foreach ($response['boletos'] as $boleto) {
73
            $boletoEntidade = new \OBRSDK\Entidades\Boletos();
74
            $boletoEntidade->setAtributos($boleto);
75
            $boletos[] = $boletoEntidade;
76
        }
77
78
        return $boletos;
79
    }
80
81
    /**
82
     * 
83
     * @param \OBRSDK\HttpClient\OBRSDK\Entidades\Abstratos\ABanco $banco
84
     * @param \OBRSDK\Entidades\Beneficiario $beneficiario
85
     * @return array
86
     */
87
    private function getBodyGerarBoletos(OBRSDK\Entidades\Abstratos\ABanco $banco, \OBRSDK\Entidades\Beneficiario $beneficiario) {
0 ignored issues
show
Bug introduced by
The type OBRSDK\HttpClient\OBRSDK...idades\Abstratos\ABanco was not found. Did you mean OBRSDK\Entidades\Abstratos\ABanco? If so, make sure to prefix the type with \.
Loading history...
88
        $boletos_dados = [];
89
        foreach ($this->boletosParaGerar as $boleto) {
90
            $boletos_dados[] = $boleto->getAtributes();
91
        }
92
93
        return [
94
            $banco->getNomeBancoJson() => $banco->getAtributes(),
95
            "beneficiario" => $beneficiario->getAtributes(),
96
            "boletos" => $boletos_dados
97
        ];
98
    }
99
100
}
101