1 | <?php |
||
2 | |||
3 | namespace Nip\Utility; |
||
4 | |||
5 | /** |
||
6 | * Class Email |
||
7 | * @package Nip\Utility |
||
8 | */ |
||
9 | class Email |
||
10 | { |
||
11 | /** |
||
12 | * @param $email |
||
13 | * @return mixed |
||
14 | */ |
||
15 | 5 | public static function mask($email) |
|
16 | { |
||
17 | 5 | if (strpos($email, '@') === false) { |
|
18 | 1 | return Str::mask($email, 1); |
|
19 | } |
||
20 | |||
21 | 4 | list($username, $domain) = explode("@", $email); |
|
22 | |||
23 | 4 | $parts[] = Str::mask($username, 1); |
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
24 | 4 | $parts[] = '@'; |
|
25 | |||
26 | 4 | $domainParts = explode('.', $domain); |
|
27 | 4 | $lastPart = array_pop($domainParts); |
|
28 | 4 | foreach ($domainParts as $part) { |
|
29 | 3 | $parts[] = Str::mask($part, 1); |
|
30 | 3 | $parts[] = '.'; |
|
31 | } |
||
32 | 4 | $parts[] = $lastPart; |
|
33 | 4 | return implode('', $parts); |
|
34 | } |
||
35 | } |
||
36 |