AbstractCNAB400Processor::createHeader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Umbrella\Ya\RetornoBoleto\Cnab\Cnab400\Convenio\Processor;
4
5
use InvalidArgumentException;
6
use Stringy\Stringy;
7
use Umbrella\Ya\RetornoBoleto\AbstractProcessor;
8
use Umbrella\Ya\RetornoBoleto\Cnab\Cnab400\Detail;
9
use Umbrella\Ya\RetornoBoleto\Cnab\Cnab400\Header;
10
use Umbrella\Ya\RetornoBoleto\Cnab\Cnab400\ITrailer;
11
use Umbrella\Ya\RetornoBoleto\Cnab\Cnab400\Trailer;
12
use Umbrella\Ya\RetornoBoleto\Cnab\ComposableInterface;
13
use Umbrella\Ya\RetornoBoleto\Exception\EmptyLineException;
14
use Umbrella\Ya\RetornoBoleto\Exception\InvalidPositionException;
15
use Umbrella\Ya\RetornoBoleto\LoteInterface;
16
use Umbrella\Ya\RetornoBoleto\Model\Banco;
17
use Umbrella\Ya\RetornoBoleto\Model\Cedente;
18
use Umbrella\Ya\RetornoBoleto\Model\Cobranca;
19
use Umbrella\Ya\RetornoBoleto\RetornoInterface;
20
21
/**
22
 * Classe abstrata para leitura de arquivos de retorno de cobranças no padrão CNAB400/CBR643.<br/>
23
 * Layout Padrão CNAB/Febraban 400 posições<br/>.
24
 * Baseado na documentação para "Layout de Arquivo Retorno para Convênios
25
 * na faixa numérica entre 000.001 a 999.999 (Convênios de até 6 posições). Versão Set/09" e
26
 * "Layout de Arquivo Retorno para convênios na faixa numérica entre 1.000.000 a 9.999.999
27
 * (Convênios de 7 posições). Versão Set/09" do Banco do Brasil
28
 * (arquivos Doc8826BR643Pos6.pdf e Doc2628CBR643Pos7.pdf)
29
 * @author Ítalo Lelis de Vietro <[email protected]>
30
 */
31
abstract class AbstractCNAB400Processor extends AbstractProcessor
32
{
33
    /**
34
     * @property int HEADER_ARQUIVO Define o valor que identifica uma coluna do tipo HEADER DE ARQUIVO
35
     */
36
    const HEADER_ARQUIVO = 0;
37
38
    /**
39
     * @property int TRAILER_ARQUIVO Define o valor que identifica uma coluna do tipo TRAILER DE ARQUIVO
40
     */
41
    const TRAILER_ARQUIVO = 9;
42
43
    public function createHeader()
44
    {
45
        return new Header();
46
    }
47
48
    public function createDetail()
49
    {
50
        return new Detail();
51
    }
52
53
    public function createTrailer()
54
    {
55
        return new Trailer();
56
    }
57
58
    /**
59
     * Processa a linha header do arquivo
60
     * @param string $linha Linha do header de arquivo processado
61
     * @return string Retorna um vetor contendo os dados dos campos do header do arquivo.
62
     */
63
    protected function processarHeaderArquivo($linha)
64
    {
65
        $header = $this->createHeader();
66
        //X = ALFANUMÉRICO 9 = NUMÉRICO V = VÍRGULA DECIMAL ASSUMIDA
67
        $header->setRegistro($linha->substr(1, 1)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
68
        $header->setTipoOperacao($linha->substr(2, 1)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
69
        $header->setIdTipoOperacao($linha->substr(3, 7)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
70
        $header->setIdTipoServico($linha->substr(10, 2)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
71
        $header->setTipoServico($linha->substr(12, 8)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
72
        $header->addComplemento($linha->substr(20, 7)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
73
74
        $bancoArray = array();
75
        if (!preg_match('#^([\d]{3})(.+)#', $linha->substr(77, 18)->trim(), $bancoArray)) {
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
76
            throw new InvalidArgumentException('Banco invalido');
77
        }
78
79
        $banco = new Banco();
80
        $banco
81
            ->setCod($bancoArray[1])
82
            ->setNome($bancoArray[2])
83
            ->setAgencia($linha->substr(27, 4)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
84
            ->setDvAgencia($linha->substr(31, 1)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
85
            ->setConta($linha->substr(32, 8)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
86
            ->setDvConta($linha->substr(40, 1)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
87
88
89
        $cedente = new Cedente();
90
        $cedente->setBanco($banco)
91
            ->setNome($linha->substr(47, 30)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
92
93
        $header->setCedente($cedente);
94
        $header->setDataGravacao($this->createDate($linha->substr(95, 6)->trim()));
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
95
        $header->setSequencialReg($linha->substr(395, 6)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
96
97
        return $header;
98
    }
99
100
    /**
101
     * Processa uma linha detalhe do arquivo.
102
     * @param string $linha Linha detalhe do arquivo processado
103
     * @return string Retorna um vetor contendo os dados dos campos da linha detalhe.
104
     */
105
    protected function processarDetalhe($linha)
106
    {
107
        $detail = $this->createDetail();
108
109
        $bancoEmissor = new Banco();
110
        $bancoEmissor
111
            ->setAgencia($linha->substr(22, 1)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
112
            ->setDvAgencia($linha->substr(31, 1)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
113
            ->setConta($linha->substr(23, 8)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
114
            ->setDvConta($linha->substr(31, 1)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
115
116
        $bancoRecebedor = new Banco();
117
        $bancoRecebedor
118
            ->setCod($linha->substr(166, 3)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
119
            ->setAgencia($linha->substr(169, 4)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
120
            ->setDvAgencia($linha->substr(173, 1)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
121
122
        $detail
123
            ->setBancoEmissor($bancoEmissor)
124
            ->setBancoRecebedor($bancoRecebedor)
125
            ->setRegistro($linha->substr(1, 1)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
126
            ->setTaxaDesconto($this->formataNumero($linha->substr(96, 5)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
127
            ->setTaxaIof($linha->substr(101, 5)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
128
            ->setCateira($linha->substr(107, 2)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
129
            ->setComando($linha->substr(109, 2)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
130
            ->setDataOcorrencia($this->createDate($linha->substr(111, 6)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
131
            ->setNumTitulo($linha->substr(117, 10)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
132
            ->setDataVencimento($this->createDate($linha->substr(147, 6)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
133
            ->setValor($this->formataNumero($linha->substr(153, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
134
            ->setEspecie($linha->substr(174, 2)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
135
            ->setDataCredito($this->createDate($linha->substr(176, 6)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
136
            ->setValorTarifa($this->formataNumero($linha->substr(182, 7)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
137
            ->setOutrasDespesas($this->formataNumero($linha->substr(189, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
138
            ->setJurosDesconto($this->formataNumero($linha->substr(202, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
139
            ->setIofDesconto($this->formataNumero($linha->substr(215, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
140
            ->setValorAbatimento($this->formataNumero($linha->substr(228, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
141
            ->setDescontoConcedido($this->formataNumero($linha->substr(241, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
142
            ->setValorRecebido($this->formataNumero($linha->substr(254, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
143
            ->setJurosMora($this->formataNumero($linha->substr(267, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
144
            ->setOutrosRecebimentos($this->formataNumero($linha->substr(280, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
145
            ->setAbatimentoNaoAprovado($this->formataNumero($linha->substr(293, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
146
            ->setValorLancamento($this->formataNumero($linha->substr(306, 13)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
147
            ->setIndicativoDc($linha->substr(319, 1)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
148
            ->setIndicadorValor($linha->substr(320, 1)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
149
            ->setValorAjuste($this->formataNumero($linha->substr(321, 12)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
150
            ->setCanalPagTitulo($linha->substr(393, 2)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
151
            ->setSequencial($linha->substr(395, 6)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
152
153
        return $detail;
154
    }
155
156
    /**
157
     * Processa a linha trailer do arquivo.
158
     * @param string $linha Linha trailer do arquivo processado
159
     * @return ITrailer Retorna um vetor contendo os dados dos campos da linha trailer do arquivo.
160
     */
161
    protected function processarTrailerArquivo($linha)
162
    {
163
        $trailer = $this->createTrailer();
164
165
        $banco = new Banco();
166
        $banco->setCod($linha->substr(5, 3)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
167
168
        $simples = new Cobranca();
169
        $simples->setQtdTitulos($linha->substr(18, 8)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
170
            ->setValorTotal($this->formataNumero($linha->substr(26, 14)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
171
            ->setNumAviso($linha->substr(40, 8)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
172
173
        $vinculada = new Cobranca();
174
        $vinculada->setQtdTitulos($linha->substr(58, 8)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
175
            ->setValorTotal($this->formataNumero($linha->substr(66, 14)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
176
            ->setNumAviso($linha->substr(80, 8)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
177
178
        $caucionada = new Cobranca();
179
        $caucionada->setQtdTitulos($linha->substr(98, 8)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
180
            ->setValorTotal($this->formataNumero($linha->substr(106, 14)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
181
            ->setNumAviso($linha->substr(120, 8)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
182
183
        $descontada = new Cobranca();
184
        $descontada->setQtdTitulos($linha->substr(138, 8)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
185
            ->setValorTotal($this->formataNumero($linha->substr(146, 14)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
186
            ->setNumAviso($linha->substr(160, 8)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
187
188
        $vendor = new Cobranca();
189
        $vendor->setQtdTitulos($linha->substr(218, 8)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
190
            ->setValorTotal($this->formataNumero($linha->substr(226, 14)->trim()))
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
191
            ->setNumAviso($linha->substr(240, 8)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
192
193
        $trailer
194
            ->setBanco($banco)
195
            ->setRegistro($linha->substr(1, 1)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
196
            ->setRetorno($linha->substr(2, 1)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
197
            ->setTipoRegistro($linha->substr(3, 2)->trim())
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
198
            ->setSimples($simples)
199
            ->setVinculada($vinculada)
200
            ->setCaucionada($caucionada)
201
            ->setDescontada($descontada)
202
            ->setVendor($vendor)
203
            ->setSequencial($linha->substr(395, 6)->trim());
0 ignored issues
show
Bug introduced by
The method substr cannot be called on $linha (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
204
        return $trailer;
205
    }
206
207
    public function processCnab(RetornoInterface $retorno, ComposableInterface $composable, LoteInterface $lote = null)
208
    {
209
        switch ((int)$composable->getRegistro()->__toString()) {
210
            case self::HEADER_ARQUIVO:
211
                $retorno->setHeader($composable);
0 ignored issues
show
Compatibility introduced by
$composable of type object<Umbrella\Ya\Retor...ab\ComposableInterface> is not a sub-type of object<Umbrella\Ya\Retor...ab\CnabHeaderInterface>. It seems like you assume a child interface of the interface Umbrella\Ya\RetornoBoleto\Cnab\ComposableInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
212
                break;
213
214
            case self::TRAILER_ARQUIVO:
215
                $retorno->setTrailer($composable);
0 ignored issues
show
Compatibility introduced by
$composable of type object<Umbrella\Ya\Retor...ab\ComposableInterface> is not a sub-type of object<Umbrella\Ya\Retor...b\CnabTrailerInterface>. It seems like you assume a child interface of the interface Umbrella\Ya\RetornoBoleto\Cnab\ComposableInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
216
                break;
217
218
            default:
219
                $lote->addDetail($composable);
0 ignored issues
show
Compatibility introduced by
$composable of type object<Umbrella\Ya\Retor...ab\ComposableInterface> is not a sub-type of object<Umbrella\Ya\Retor...ab\CnabDetailInterface>. It seems like you assume a child interface of the interface Umbrella\Ya\RetornoBoleto\Cnab\ComposableInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Bug introduced by
It seems like $lote is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
220
                break;
221
        }
222
    }
223
224
    /**
225
     * Processa uma linha do arquivo de retorno.
226
     * @param int $numLn Número_linha a ser processada
227
     * @param string $linha String contendo a linha a ser processada
228
     * @return IComposable Retorna um vetor associativo contendo os valores_linha processada.
229
     */
230
    public function processarLinha($numLn, Stringy $linha)
231
    {
232
        $tamLinha = 400; //total de caracteres das linhas do arquivo
233
        //o +2 é utilizado para contar o \r\n no final da linha
234
        if (strlen($linha) != $tamLinha && strlen($linha) != $tamLinha + 2) {
235
            throw new InvalidPositionException("A linha $numLn não tem $tamLinha posições. Possui " . strlen($linha));
236
        }
237
238
        if (trim($linha) == "") {
239
            throw new EmptyLineException("A linha $numLn está vazia.");
240
        }
241
242
        //é adicionado um espaço vazio no início_linha para que
243
        //possamos trabalhar com índices iniciando_1, no lugar_zero,
244
        //e assim, ter os valores_posição_campos exatamente
245
        //como no manual CNAB400
246
        $linha = $linha->insert(" ", 0);
247
        $tipoLn = $linha->substr(1, 1)->trim();
248
249
        $this->needToCreateLote = false;
250
        if ((string)$tipoLn == static::HEADER_ARQUIVO) {
251
            $this->needToCreateLote = true;
252
            $vlinha = $this->processarHeaderArquivo($linha);
253
        } elseif ((string)$tipoLn == static::DETALHE) {
254
            $vlinha = $this->processarDetalhe($linha);
255
        } elseif ((string)$tipoLn == static::TRAILER_ARQUIVO) {
256
            $vlinha = $this->processarTrailerArquivo($linha);
257
        } else {
258
            $vlinha = null;
259
        }
260
        return $vlinha;
261
    }
262
}
263