Boleto   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 244
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 11
c 7
b 1
f 0
lcom 1
cbo 6
dl 0
loc 244
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
B processaDadosBoleto() 0 43 1
A getAtributosParser() 0 4 1
B parseAttributes() 0 24 6
A adicionaDemonstrativo() 0 6 1
A adicionaInstrucao() 0 6 1
getLinhaDigitavelFormatada() 0 1 ?
getNossoNumeroFormatado() 0 1 ?
getCodigoBarras() 0 1 ?
getAgenciaCodigoBeneficiarioDv() 0 1 ?
1
<?php
2
namespace CbCaio\Boletos\Models\Boletos\Base;
3
4
use  CbCaio\Boletos\Generators\Barcode;
0 ignored issues
show
Coding Style introduced by
There must be a single space after the USE keyword
Loading history...
5
use  CbCaio\Boletos\Models\Bancos\Contracts\BancoInterface;
0 ignored issues
show
Coding Style introduced by
There must be a single space after the USE keyword
Loading history...
6
use  CbCaio\Boletos\Models\Beneficiario\Contracts\BeneficiarioInterface;
0 ignored issues
show
Coding Style introduced by
There must be a single space after the USE keyword
Loading history...
7
use  CbCaio\Boletos\Models\BoletoInfo\Contracts\BoletoInfoInterface;
0 ignored issues
show
Coding Style introduced by
There must be a single space after the USE keyword
Loading history...
8
use  CbCaio\Boletos\Models\Boletos\Contracts\BoletoInterface;
0 ignored issues
show
Coding Style introduced by
There must be a single space after the USE keyword
Loading history...
9
use  CbCaio\Boletos\Models\Pagador\Contracts\PagadorInterface;
0 ignored issues
show
Coding Style introduced by
There must be a single space after the USE keyword
Loading history...
10
11
abstract class Boleto implements BoletoInterface
12
{
13
    private   $atributos_parser    = [
14
        ':taxa',
15
        ':multa',
16
        ':vencimento'
17
    ];
18
    public $beneficiario;
19
    public $pagador;
20
    public $info;
21
    public    $banco;
22
    public    $demonstrativo_array = [];
23
    public    $instrucoes_array    = [];
24
    public    $bars                = [];
25
    public    $processed           =
26
        [
27
            /* --------[A]------- */
28
            'codigo_banco_compensacao'    => '',
29
            'linha_digitavel'             => '',
30
            /* --------[B]------- */
31
            'local_de_pagamento'          => "PREFERENCIALMENTE NAS CASAS LOTÉRICAS ATÉ O VALOR LIMITE",
32
            'vencimento'                  => 'DD/MM/AAAA',
33
            /* --------[C]------- */
34
35
            'beneficiario'                =>
36
                [
37
                    'razao_social' => 'Razão Social ou Nome Fantasia do Beneficiário',
38
                    'cpf_cnpj'     => 'CPF/CNPJ*',
39
                    'endereco'     => 'endereco',
40
                    'cidade'       => 'cidade'
41
                ],
42
            /*
43
             * Formato AAAA / XXXXXX-DV, onde:
44
             * AAAA: Código da Agência do Beneficiário
45
             * XXXXXX: Código do Beneficiário
46
             * DV: Dígito Verificador do Código do Beneficiário (Módulo 11), conforme Anexo VI
47
             */
48
            'agencia_codigo_beneficiario' => 'AAAA / XXXXXX-DV',
49
            /* --------[D]------- */
50
51
            'data_do_documento'           => 'DD/MM/AAAA',
52
            /*
53
             * Também chamado de "Seu Número", é o número utilizado
54
             * e controlado pelo Beneficiário para identificar o título de cobrança
55
             */
56
            'nr_do_documento'             => '',
57
            'especie_doc'                 => '',
58
            'aceite'                      => '',
59
            'data_do_processamento'       => 'DD/MM/AAAA',
60
            /*
61
             * - Formato: XYNNNNNNNNNNNNNNN-D, onde:
62
             *  X Modalidade/Carteira de Cobrança (1-Registrada/2-Sem Registro)
63
             *  Y Emissão do boleto (4-Beneficiário)
64
             *  NNNNNNNNNNNNNNN Nosso Número (15 posições livres do Beneficiário)
65
             *  D Dígito Verificador
66
             */
67
            'nosso_numero'                => 'XYNNNNNNNNNNNNNNN-D',
68
            /* --------[E]------- */
69
            'carteira'                    => 'SR ou RG',
70
            'especie_moeda'               => 'R$',
71
            'valor_documento'             => '< R$ 9.999.999,99',
72
            'uso_do_banco'                => NULL,//'não preencher',
73
            'qtde_moeda'                  => NULL,//'não preencher',
74
            'xValor'                      => NULL,//'não preencher',
75
76
            /* --------[F]------- */
77
            'instrucoes'                  => [],
78
            'desconto'                    => NULL, //'não preencher',
79
80
            /* --------[G]------- */
81
            /*'juros'                       => NULL,'não preencher',*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
82
83
            /* --------[H]------- */
84
            /*'valor_cobrado'               => NULL,'não preencher',*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
85
86
            /* --------[I]------- */
87
            'pagador'                     =>
88
                [
89
                    'nome'              => NULL,
90
                    'endereco'          => NULL,
91
                    'cidade_estado_cep' => NULL,
92
                    'cpf_cnpj'          => NULL
93
                    //'Obrigatório na Cobrança Registrada.'
94
                ]
95
            ,
96
            'sacador'                     =>
97
                [
98
                    'nome'     => 'emitente original do documento que originou o boleto de cobrança',
99
                    'cpf_cnpj' => ''
100
                ]
101
            ,
102
            /* --------[J]------- */
103
104
            'codigo_de_barras'            => ''
105
        ];
106
107
    /**
108
     * @param BancoInterface        $banco
109
     * @param BeneficiarioInterface $beneficiario
110
     * @param PagadorInterface      $pagador
111
     * @param BoletoInfoInterface   $info
112
     */
113
    public function __construct(
114
        BancoInterface $banco,
115
        BeneficiarioInterface $beneficiario,
116
        PagadorInterface $pagador,
117
        BoletoInfoInterface $info
118
    )
119
120
    {
121
        $this->beneficiario = $beneficiario;
122
        $this->banco        = $banco;
123
        $this->info         = $info;
124
        $this->pagador      = $pagador;
125
    }
126
127
    /**
128
     * Função responsável por processar os dados que serão impressos no boleto
129
     */
130
    public function processaDadosBoleto()
131
    {
132
        $this->processed['codigo_banco_compensacao'] = $this->banco->getCodigoCompensacao();
133
        $this->processed['linha_digitavel']          = $this->getLinhaDigitavelFormatada();
134
        $this->processed['beneficiario']             =
135
            [
136
                'razao_social' => $this->beneficiario->getRazaoSocial(),
137
                'agencia'      => $this->beneficiario->getAgencia(),
138
                'cpf_cnpj'     => $this->beneficiario->getCpfCnpj(),
139
                'endereco'     => $this->beneficiario->getEndereco(),
140
                'cidade'       => $this->beneficiario->getCidadeEstado()
141
            ];
142
        $this->processed['nosso_numero']             = $this->getNossoNumeroFormatado();
143
        $this->processed['nr_do_documento']          = $this->info->getNumeroDocumento();
144
        $this->processed['valor_documento']          = $this->info->getValorFinal();
145
        $this->processed['especie_doc']              = $this->info->getEspecieDoc();
146
        $this->processed['aceite']                   = $this->info->getAceite();
147
        $this->processed['carteira']                 = $this->beneficiario->getCarteira();
148
149
        $this->processed['vencimento']                  = $this->info->getDataVencimentoCalculada();
150
        $this->processed['agencia_codigo_beneficiario'] = $this->getAgenciaCodigoBeneficiarioDv();
151
        $this->processed['data_do_documento']           = $this->info->getDataDocumento();
152
        $this->processed['data_do_processamento']       = $this->info->getDataProcessamento();
153
        $this->processed['carteira']                    = $this->beneficiario->getCarteira();
154
        $this->processed['especie_moeda']               = $this->info->getEspecieMoeda();
155
        $this->processed['pagador']                     =
156
            [
157
                'nome'              => $this->pagador->getNome(),
158
                'endereco'          => $this->pagador->getEndereco(),
159
                'cidade_estado_cep' => $this->pagador->getCidadeEstadoCep(),
160
                'cpf_cnpj'          => $this->pagador->getCpfCnpj(),
161
            ];
162
        $this->processed['sacador']                     =
163
            [
164
                'nome'     => $this->info->getNomeSacado(),
165
                'cpf_cnpj' => $this->info->getCpfCnpjSacado()
166
            ];
167
168
        $this->processed['codigo_de_barras'] = $this->getCodigoBarras();
169
        $barcodeGenerator                    = new Barcode();
170
        $this->bars                          =
171
            $barcodeGenerator->getBarcode($this->getCodigoBarras(), $barcodeGenerator::TYPE_INTERLEAVED_2_5)['bars'];
172
    }
173
174
    /**
175
     * @return array
176
     */
177
    private function getAtributosParser()
178
    {
179
        return $this->atributos_parser;
180
    }
181
182
    /**
183
     * @param string $string
184
     * @return string
185
     */
186
    protected function parseAttributes($string)
187
    {
188
        foreach ($this->getAtributosParser() as $attribute)
189
        {
190
            if (strpos($string, $attribute) !== FALSE)
191
            {
192
                switch ($attribute)
193
                {
194
                    case ":taxa":
195
                        $string = preg_replace("/$attribute" . '\b/', $this->info->getValorTaxa(), $string);
196
                        break;
197
                    case ":multa":
198
                        $string = preg_replace("/$attribute" . '\b/', $this->info->getValorMulta(), $string);
199
                        break;
200
                    case ":vencimento":
201
                        $string = preg_replace("/$attribute" . '\b/',
202
                                               $this->info->getDataVencimentoCalculada()->format('d/m/Y'), $string);
203
                        break;
204
                }
205
            }
206
        }
207
208
        return $string;
209
    }
210
211
    /**
212
     * @param string $string
213
     * @return $this
214
     */
215
    public function adicionaDemonstrativo($string)
216
    {
217
        $this->demonstrativo_array[] = $this->parseAttributes($string);
218
219
        return $this;
220
    }
221
222
    /**
223
     * @param string $string
224
     * @return $this
225
     */
226
    public function adicionaInstrucao($string)
227
    {
228
        $this->instrucoes_array[] = $this->parseAttributes($string);
229
230
        return $this;
231
    }
232
233
    /**
234
     * @return string
235
     */
236
    public abstract function getLinhaDigitavelFormatada();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
237
238
    /**
239
     * @return string
240
     */
241
    public abstract function getNossoNumeroFormatado();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
242
243
    /**
244
     * @return string
245
     */
246
    public abstract function getCodigoBarras();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
247
248
    /**
249
     * @return string
250
     */
251
    public abstract function getAgenciaCodigoBeneficiarioDv();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
252
253
254
}