Issues (1)

Helpers/Helpers.php (1 issue)

1
<?php
2
/*
3
 * Copyright (c) 2021. Leandro Passos
4
 */
5
6
/**
7
 * Função mask_document
8
 * Aplica a máscara de pontuação para ser exibida na tela
9
 *
10
 * @param string $document
11
 * @param string $chars
12
 * @param string $mask
13
 * @param int $index
14
 * @return string
15
 */
16
function mask_document(string $document, string $chars, string $mask = '', int $index = 0): string
17
{
18
    for ($i = 0; $i <= strlen($chars) - 1; $i++) {
19
        if ($chars[$i] == '*' || $chars[$i] == '#') {
20
            if (isset($document[$index])) {
21
                $mask .= $document[$index++];
22
            }
23
        } else {
24
            if (isset($chars[$i])) {
25
                $mask .= $chars[$i];
26
            }
27
        }
28
    }
29
30
    return $mask;
31
}
32
33
/**
34
 * Função hide_document
35
 * Oculta caracteres de certos documentos exibidos na tela - ideal para projetos adequados ou em processo de
36
 * adequação à Lei Geral de Proteção de Dados (LGPD)
37
 *
38
 * @param string|null $document
39
 * @return string|null
40
 */
41
function hide_document(string $document): ?string
42
{
43
    if ($document) {
44
        return ((strlen($document) === 18)
0 ignored issues
show
Bug Best Practice introduced by
The expression return strlen($document)...'***.***.***', -14, 11) could return the type array which is incompatible with the type-hinted return null|string. Consider adding an additional type-check to rule them out.
Loading history...
45
            ? substr_replace($document, '**.***.***/****', -18, 15)
46
            : substr_replace($document, '***.***.***', -14, 11));
47
    }
48
49
    return null;
50
}