Issues (30)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Models/Boletos/BoletoCEF.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace CbCaio\Boletos\Models\Boletos;
3
4
use CbCaio\Boletos\Calculators\Calculator;
5
use CbCaio\Boletos\Models\Bancos\BancoCEF;
6
use CbCaio\Boletos\Models\Beneficiario\BeneficiarioCEF;
7
use CbCaio\Boletos\Models\BoletoInfo\BoletoInfo;
8
use CbCaio\Boletos\Models\Boletos\Base\Boleto;
9
use Carbon\Carbon;
10
use CbCaio\Boletos\Models\Pagador\Pagador;
11
12
class BoletoCEF extends Boleto
13
{
14
    protected $date_format = 'Y-m-d';
15
16
    /**
17
     * @param BancoCEF        $banco
18
     * @param BeneficiarioCEF $beneficiario
19
     * @param Pagador         $pagador
20
     * @param BoletoInfo      $info
21
     */
22
    public function __construct(
23
        BancoCEF $banco,
24
        BeneficiarioCEF $beneficiario,
25
        Pagador $pagador,
26
        BoletoInfo $info
27
    )
28
    {
29
        parent::__construct(
30
            $banco, $beneficiario, $pagador, $info
31
        );
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getCodigoBarras()
38
    {
39
        $codigo_barras =
40
            $this->getCodigoBarrasInicio() .
41
            $this->calculaDVGeralCodigoBarras() .
42
            $this->getCodigoBarrasFinal();
43
44
        return "$codigo_barras";
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getLinhaDigitavelFormatada()
51
    {
52
        return $this->formataLinhaDigitavel($this->calculaLinhaDigitavel());
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getNossoNumeroFormatado()
59
    {
60
        $nosso_numero_sem_dv = $this->getNossoNumeroSemDV();
61
        $parte_1             = substr($nosso_numero_sem_dv, 0, 2);
62
        $parte_2             = substr($nosso_numero_sem_dv, 2, 15);
63
        $parte_3             = $this->calculaDVNossoNumero($this->getNossoNumeroSemDV());
64
65
        return $parte_1 . '/' . $parte_2 . '-' . $parte_3;
66
    }
67
68
    /**
69
     * @param string $linha_digitavel
70
     * @return string
71
     */
72
    public function formataLinhaDigitavel($linha_digitavel)
73
    {
74
        $campo_1 = substr($linha_digitavel, 0, 5) . '.' . substr($linha_digitavel, 5, 5) . ' ';
75
        $campo_2 = substr($linha_digitavel, 10, 5) . '.' . substr($linha_digitavel, 15, 6) . ' ';
76
        $campo_3 = substr($linha_digitavel, 21, 5) . '.' . substr($linha_digitavel, 26, 6) . ' ';
77
        $campo_4 = substr($linha_digitavel, 32, 1) . ' ';
78
        $campo_5 = substr($linha_digitavel, 33, 14);
79
80
        return $campo_1 . $campo_2 . $campo_3 . $campo_4 . $campo_5;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    protected function getCodigoBarrasInicio()
87
    {
88
        $banco = $this->banco;
89
90
        return $banco->getCodigoBanco() . $banco->getCodigoMoeda();
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    protected function getCodigoBarrasFinal()
97
    {
98
        $codigo_barras_final = $this->calculaFatorVencimento($this->info->getDataVencimentoCalculada()) .
99
            $this->info->getValorFinal(TRUE, TRUE) .
100
            $this->beneficiario->getCodigoBeneficiario() .
101
            $this->calculaDVCodigoBeneficiario() .
102
            $this->getNossoNumeroSeq1() .
103
            $this->getNossoNumeroConst1() .
104
            $this->getNossoNumeroSeq2() .
105
            $this->getNossoNumeroConst2() .
106
            $this->getNossoNumeroSeq3() .
107
            $this->calculaDVCampoLivre();
108
109
        return "$codigo_barras_final";
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    protected function getCodigoDeBarrasSemDV()
116
    {
117
        $codigo_barras_sem_dv = $this->getCodigoBarrasInicio() . $this->getCodigoBarrasFinal();
118
119
        return $codigo_barras_sem_dv;
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    protected function calculaLinhaDigitavel()
126
    {
127
        $codigo_barras  = $this->getCodigoBarras();
128
        $campo_1_sem_dv =
129
            substr($codigo_barras, 0, 3) .
130
            substr($codigo_barras, 3, 1) .
131
            substr($codigo_barras, 19, 5);
132
133
        $campo_1 =
134
            $campo_1_sem_dv .
135
            $this->calculaDVLinhaDigitavel($campo_1_sem_dv);
136
137
        $campo_2_sem_dv = substr($codigo_barras, 24, 10);
138
        $campo_2        =
139
            $campo_2_sem_dv .
140
            $this->calculaDVLinhaDigitavel($campo_2_sem_dv);
141
142
        $campo_3_sem_dv = substr($codigo_barras, 34, 10);
143
        $campo_3        =
144
            $campo_3_sem_dv .
145
            $this->calculaDVLinhaDigitavel($campo_3_sem_dv);
146
147
        $campo_4 = substr($codigo_barras, 4, 1);
148
        $campo_5 =
149
            substr($codigo_barras, 5, 4) .
150
            Calculator::formataNumero(substr($codigo_barras, 9, 10), 10, 0);
151
152
        $linha_digitavel = $campo_1 . $campo_2 . $campo_3 . $campo_4 . $campo_5;
153
154
        return $linha_digitavel;
155
    }
156
157
    /**
158
     * @return string
159
     */
160
    protected function getCampoLivreDoCodigoDeBarras()
161
    {
162
        $campo_livre_sem_dv = $this->getCampoLivreSemDV();
163
        $dv_campo_livre     = $this->calculaDVCampoLivre($campo_livre_sem_dv);
164
165
        return "$campo_livre_sem_dv$dv_campo_livre";
166
    }
167
168
    /**
169
     * @param string $nosso_numero
170
     * @return string
171
     */
172
    public function formataNossoNumeroSemDV($nosso_numero)
173
    {
174
        $nosso_numero_sem_dv = str_replace('/', "", $nosso_numero);
175
        $nosso_numero_sem_dv = preg_replace('/(\-.\b)/', "", $nosso_numero_sem_dv);
176
177
        return "$nosso_numero_sem_dv";
178
    }
179
180
    /**
181
     * @param Carbon|string $data_vencimento
182
     * @return string
183
     */
184
    public function calculaFatorVencimento($data_vencimento)
185
    {
186
        if ($data_vencimento == NULL)
187
        {
188
            return "0000";
189
        }
190
191
        if (!($data_vencimento instanceof Carbon))
192
        {
193
            $data_vencimento = Carbon::createFromFormat($this->date_format, $data_vencimento)->setTime(0, 0, 0);
194
        }
195
196
        $data_base      = Carbon::create(1997, 10, 7, 0);
197
        $diferenca_dias = $data_base->diffInDays($data_vencimento);
198
199
        return "$diferenca_dias";
200
    }
201
202
    /**
203
     * @param string $nosso_numero_sem_dv
204
     * @return int
205
     */
206
    public function calculaDVNossoNumero($nosso_numero_sem_dv = NULL)
207
    {
208
        $peso_inferior = 2;
0 ignored issues
show
$peso_inferior is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
209
        $peso_superior = 9;
0 ignored issues
show
$peso_superior is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
210
211
        if ($nosso_numero_sem_dv === NULL)
212
        {
213
            $nosso_numero = $this->getNossoNumeroSemDV();
214
        } else
215
        {
216
            $nosso_numero = $nosso_numero_sem_dv;
217
        }
218
        $soma_resultados = Calculator::getResultadoSomaModulo11($nosso_numero);
219
        $resto_divisao   = $soma_resultados % 11;
220
        $valor_final     = 11 - $resto_divisao;
221
222
        if ($valor_final > 9)
223
        {
224
            return 0;
225
        } else
226
        {
227
            return $valor_final;
228
        }
229
    }
230
231
    /**
232
     * @param string $codigo_beneficiario
233
     * @return int
234
     */
235
    public function calculaDVCodigoBeneficiario($codigo_beneficiario = NULL)
236
    {
237
        if ($codigo_beneficiario === NULL)
238
        {
239
            return Calculator::calculaModulo11($this->beneficiario->getCodigoBeneficiario());
240
        } else
241
        {
242
            return Calculator::calculaModulo11($codigo_beneficiario);
243
        }
244
    }
245
246
    /**
247
     * @param string $campo
248
     * @return int
249
     */
250
    public function calculaDVLinhaDigitavel($campo)
251
    {
252
        return Calculator::calculaModulo10("$campo");
253
    }
254
255
    /**
256
     * @param string $codigo_barras_sem_dv
257
     * @return int
258
     */
259
    public function calculaDVGeralCodigoBarras($codigo_barras_sem_dv = NULL)
260
    {
261
        if ($codigo_barras_sem_dv === NULL)
262
        {
263
            return Calculator::calculaModulo11SemDV0($this->getCodigoDeBarrasSemDV());
264
        } else
265
        {
266
            return Calculator::calculaModulo11SemDV0($codigo_barras_sem_dv);
267
        }
268
    }
269
270
    /**
271
     * @param string $campo_livre_sem_dv
272
     * @return int
273
     */
274
    public function calculaDVCampoLivre($campo_livre_sem_dv = NULL)
275
    {
276
        if ($campo_livre_sem_dv === NULL)
277
        {
278
            return Calculator::calculaModulo11($this->getCampoLivreSemDV());
279
        } else
280
        {
281
            return Calculator::calculaModulo11($campo_livre_sem_dv);
282
        }
283
    }
284
285
    /**
286
     * @return string
287
     */
288
    private function getNossoNumeroConst1()
289
    {
290
        return substr($this->getNossoNumeroSemDV(), 0, 1);
291
    }
292
293
    /**
294
     * @return string
295
     */
296
    private function getNossoNumeroConst2()
297
    {
298
        return substr($this->getNossoNumeroSemDV(), 1, 1);
299
    }
300
301
    /**
302
     * @return string
303
     */
304
    private function getNossoNumeroSeq1()
305
    {
306
        return substr($this->getNossoNumeroSemDV(), 2, 3);
307
    }
308
309
    /**
310
     * @return string
311
     */
312
    private function getNossoNumeroSeq2()
313
    {
314
        return substr($this->getNossoNumeroSemDV(), 5, 3);
315
    }
316
317
    /**
318
     * @return string
319
     */
320
    private function getNossoNumeroSeq3()
321
    {
322
        return substr($this->getNossoNumeroSemDV(), 8, 9);
323
    }
324
325
    /**
326
     * @return string
327
     */
328
    private function getCampoLivreSemDV()
329
    {
330
        $campo_livre_parcial =
331
            $this->beneficiario->getCodigoBeneficiario() .
332
            $this->calculaDVCodigoBeneficiario($this->beneficiario->getCodigoBeneficiario()) .
333
            $this->getNossoNumeroSeq1() .
334
            $this->getNossoNumeroConst1() .
335
            $this->getNossoNumeroSeq2() .
336
            $this->getNossoNumeroConst2() .
337
            $this->getNossoNumeroSeq3();
338
339
        return "$campo_livre_parcial";
340
    }
341
342
    /**
343
     * @return string
344
     */
345
    public function getNossoNumeroSemDV()
346
    {
347
        $nosso_numero_recebido = $this->info->getNossoNumeroRecebido();
348
349
        if (strlen($nosso_numero_recebido) == 15)
350
        {
351
            $nosso_numero_recebido = $this->banco->getInicioNossoNumero() . $nosso_numero_recebido;
352
        }
353
354
        return $this->formataNossoNumeroSemDV($nosso_numero_recebido);
355
    }
356
357
    public function getAgenciaCodigoBeneficiarioDv()
358
    {
359
        $codigo_beneficiario = $this->beneficiario->getCodigoBeneficiario();
360
        $agencia             = $this->beneficiario->getAgencia();
361
        $dv                  = $this->calculaDVCodigoBeneficiario($codigo_beneficiario);
362
363
        return $agencia . ' / ' . $codigo_beneficiario . '-' . $dv;
364
    }
365
}