Skip to content

Commit

Permalink
Update BoletoValidatorWebformHandler.php
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagogomesverissimo authored Nov 14, 2024
1 parent 7390e29 commit 8c8d74d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Plugin/WebformHandler/BoletoValidatorWebformHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function validateBoletoUSP(FormStateInterface $formState, WebformSubmiss
/* Validação do cpf */
if(!empty($cpf_key) && !empty(trim($data[$cpf_key])) ){
$cpf = \Drupal::service('cpf')->digits($data[$cpf_key]);
if(!\Drupal::service('cpf')->isValid($cpf)) {
if(!!$this->validaCPF($cpf)) {
$formState->setErrorByName($cpf_key,
$this->t('O número de CPF %cpf não é válido', ['%cpf' => $data[$cpf_key]]));
}
Expand All @@ -83,5 +83,26 @@ private function validateBoletoUSP(FormStateInterface $formState, WebformSubmiss
/* TODO: validação objeto de cobrança */

/* TODO: validação objeto sacado */

private function validaCPF($cpf) {
$cpf = preg_replace( '/[^0-9]/is', '', $cpf );
if (strlen($cpf) != 11) {
return false;
}
if (preg_match('/(\d)\1{10}/', $cpf)) {
return false;
}
for ($t = 9; $t < 11; $t++) {
for ($d = 0, $c = 0; $c < $t; $c++) {
$d += $cpf[$c] * (($t + 1) - $c);
}
$d = ((10 * $d) % 11) % 10;
if ($cpf[$c] != $d) {
return false;
}
}
return true;
}

}
}

0 comments on commit 8c8d74d

Please sign in to comment.